Bug 240157 - cp has no ability to preserve extended attributes when copying a file
Summary: cp has no ability to preserve extended attributes when copying a file
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL: https://bugs.freebsd.org/bugzilla/sho...
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-27 22:10 UTC by Sean McBride
Modified: 2022-12-17 22:54 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sean McBride 2019-08-27 22:10:55 UTC
I was very surprised to see that neither 'cp -p' nor 'cp -a' preserve the extended attributes of a file.

example:

root@freenas[/test]# lsextattr user A.txt 
A.txt	DosStream.com.apple.TextEncoding:$DATA	DosStream.AFP_Resource:$DATA	DosStream.AFP_AfpInfo:$DATA	DOSATTRIB	DosStream.com.apple.lastuseddate#PS:$DATA


root@freenas[/test]# cp -a A.txt A2.txt      


root@freenas[/test]# lsextattr user A2.txt
A2.txt


EAs sometimes contain important data, and there should surely be some kind of option to preserve them when copying a file.

In contrast, macOS's cp -p does preserve EAs.

See also #240146 for related bug against the cp man page for saying nothing.
Comment 1 Conrad Meyer freebsd_committer freebsd_triage 2019-08-27 22:26:32 UTC
We don't have a good "Related" bug field and 240146 doesn't have a blocking relationship with this one, so I just stuck it in the URL field for easier lookup.
Comment 2 Andrey V. Elsukov freebsd_committer freebsd_triage 2019-08-28 09:37:17 UTC
Some time ago I saw patches for find(1) and cp(1). If someone wants to look at, you can find them here: 

https://gist.github.com/scifinder
https://rxlab.org/text/?id=33
Comment 3 Conrad Meyer freebsd_committer freebsd_triage 2019-08-29 04:19:32 UTC
It seems they have created github repos for the modified versions:

https://github.com/scifinder/cp
https://github.com/scifinder/find
Comment 4 Conrad Meyer freebsd_committer freebsd_triage 2019-08-29 04:20:46 UTC
...although the git repos are less useful than than just the patches.
Comment 5 John Higgins 2022-12-16 18:59:09 UTC
(In reply to Conrad Meyer from comment #4)
I'm new to this project and I'd love to work on this.

I applied the patch mentioned in the above conversation to the current source code. I ran the 'cp' tests and all 11 of them succeeded. I was going to start writing tests for verifying that extended attributes are copied but I can't seem to find any shell commands that interact with them. I've read some of the documentation and it seems that you can use the 'zfs' command to figure out if a file system has extended attributes turned on but it doesn't allow you to set them on a per file basis.

Does anyone have any advice on what I should be using?
Comment 6 Yuri 2022-12-16 22:50:50 UTC
(In reply to John Higgins from comment #5)
Initial post shows lsextattr command, you can lookup other related commands doing `man lsextattr`.
Comment 7 John Higgins 2022-12-17 22:54:49 UTC
(In reply to Yuri from comment #6)
Thanks for the help :) I got a test working for the scifinder patch using Kyua. The only problem is that I'm not sure what to do when extended attributes are not enabled for the current file system. Is there a way to conditionally run tests or should I set the test to automatically succeed if the system doesn't support extended attributes?