directory
directory copied to clipboard
[Feature request] A way to copy a directory with metadata (and/or recursively)
There is no equivalent to the popular cp -a
available.
It is similar to copyFileWithMetadata
, but for entire directories. It is also very strict about including all metadata (even xargs).
cp -a
works recursively, and I’d argue that that’s the main case where copying the metadata makes sense, but maybe the option to only copy the directory metadata and not the files in there should be left open.
So maybe a generic copyMetadata
that works on files, directories, symlinks, and everything else, because it only alters the metadata, which is only stored in the parent directory, and accessible via stat
and xattr
.
copyPathRecursivelyWithMetadata
(or archivePath
?) could then be implemented on top of that.
Is that a good thing to add?
Given that copyFileWithMetadata
exists, a straightforward extension to support recursive copying should be reasonably within scope of directory
.
I'm not so sure how far we want to extend the kinds of metadata supported beyond current set. If it's in POSIX then one could make an argument for it, but if it's specific to a niche file system then the implementation can become hard to maintain or even test.
and
xargs
Whoops, I meant xattr
if it's specific to a niche file system then the implementation can become hard to maintain or even test.
Yes, I agree.
Extended file attributes are quite common though, supported by pretty much all Unix OSes, including GNU (e.g. in coreutils (like in cp
), plus all major file systems), and even by Windows. On Linux, they are used for access control lists (which is where my interest in them comes from), SELinux, KDE’s metadata framework, Chromium, OpenStack, etc.
So according to the first technical editor for POSIX.1e, which specified them, the standard effort was a success, even though the POSIX.1e draft was withdrawn due to politics. I also don’t know how much they are actually used in practice, outside of my systems. :)
So, I guess it depends on what feels right for you. (If it’s not worth it, then nevermind. :)
A quick check on a normal Linux (Mint) system showed the following xattrs to be used:
security.capability system.posix_acl_access system.posix_acl_default system.sockprotoname trusted.delegate trusted.invocation_id user.baloo.rating # By KDE’s metadata framework (in a backup from another system) user.birthtime # by WebKit user.coredump.comm user.coredump.exe user.coredump.gid user.coredump.hostname user.coredump.pid user.coredump.rlimit user.coredump.signal user.coredump.timestamp user.coredump.uid user.crtime_usec user.DOSATTRIB # by files coming from FAT, I guess user.dublincore.contributor # By videos user.dublincore.date user.dublincore.description user.dublincore.format user.dublincore.title user.random-seed-creditable user.xdg.referrer.url # Also by videos
Though by far the most files have none.
@Rufflewind is this something you're still keen on? Would love to give it a shot.
There is uncertainty regarding the scope of what metadata gets copied. Maybe, it'd be useful to have some sort of generic recursive copier, e.g.
data Copier = Copier { copyMetadata :: OsPath -> OsPath -> IO () }
copyRecursively :: Copier -> OsPath -> OsPath -> IO ()
That way the client can customize copyMetadata
to fit their needs. Thoughts?