Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] A way to copy a directory with metadata (and/or recursively) #160

Open
navid-zamani opened this issue Jul 25, 2023 · 5 comments
Labels
type: a-feature-request This is a request for a new feature.

Comments

@navid-zamani
Copy link

navid-zamani commented Jul 25, 2023

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?

@Rufflewind
Copy link
Member

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.

@Rufflewind Rufflewind added the type: a-feature-request This is a request for a new feature. label Jul 27, 2023
@navid-zamani
Copy link
Author

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. :)

@navid-zamani
Copy link
Author

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.

@ameya-deshmukh
Copy link

@Rufflewind is this something you're still keen on? Would love to give it a shot.

@Rufflewind
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: a-feature-request This is a request for a new feature.
Projects
None yet
Development

No branches or pull requests

3 participants