pyfilesystem2
pyfilesystem2 copied to clipboard
Copying metadata between FS objects
Hi!
I'm looking for a way to copy/mirror data from ReadTarFS
to OSFS
. Everything works fine unless the archive contains symlinks. All copy/mirror methods are implemented via copy_file_internal
function which in turn calls openbin
method of appropriate FS-inherited object. And in ReadTarFS
implementation of openbin
there is
if not member.isfile():
raise errors.FileExpected(path)
I get why this check is there - the library strives to be a lowest common denominator for different filesystems and symlinks are not universally-supported. I believe that my current issue can be solved by patching if not member.isfile()
to if not (member.isfile() or member.issym())
and using fs.copy.copy_fs
with on_copy
callback to alter metadata with setinfo
call (as symlinks are simply text files with magic attribute set on them).
But it feels that a more general problem lurks there. Currently there is no sane way to customize copying (of both data and metadata) for cases when both filesystems actually support the same set of features and thus it's safe to copy some exotic types of files (like symlinks/sockets/devices/... in tar and ext4).
I like the idea behind this library but lack of such feature makes it unusable for my case. Off the top of my head I can think of one solution. What do you think about it?
PS: Thanks for your time and for an interesting piece of software! =)
I think the issue here is actually coming from the ReadTarFS
implementation.
If you look at the implementation of OSFS
(which also powers AppFS
and TempFS
), openbin
will follow the symlink and simply open the linked file. Now, Pyfilesystem2 does not really have a clear behaviour related to symbolic links, but I'd expect them to just work if the link happens to point to a file.