Open dechamps opened 1 month ago
Currently shutil.copy
just read/writes the files and copies them (more or less efficiently using sendfile(2)
if possible). In addition, SEEK_HOLE is not present on all kernel versions (and not all FS support it for the same kernel version).
So, unless you find a way to do it without those, I don't think we can make it happen for now =/ (well, we could by reading the entire file, looking for sparse regions, and then make it sparse as well, but I wouldn't do it by default though).
I will categorize this one as a feature rather than a bug (because it does what it should do, namely copying the file).
SEEK_HOLE is not present on all kernel versions (and not all FS support it for the same kernel version)
Why not just try it and fall back to normal copy if it's not supported?
I wouldn't do it by default though
cp
does it by default, so it doesn't seem unreasonable to me for a high-level Python copy library to do it as well. cp(1)
:
By default, sparse SOURCE files are detected by a crude heuristic and the corresponding DEST file is made sparse as well.
I'll ask experts on those questions:
cc @barneygale (I know you work on path-related topics but I don't know if there are more people working on this topic).
My own opinion on the topic itself is that I don't mind the feature. But I don't know how much work it requires (I'm also not sure whether we want to duplicate the behaviour of cp
actually).
Bug report
Bug description:
Ideally
shutil.copy2()
should be capable of copying sparse files without unnecessarily expanding them (this is the default behavior ofcp
).This could potentially be implemented using
lseek(2)
SEEK_DATA
andSEEK_HOLE
.CPython versions tested on:
3.12
Operating systems tested on:
Linux