cache icon indicating copy to clipboard operation
cache copied to clipboard

Feature request: Add extended attributes support with tar flag

Open williamtheaker opened this issue 3 years ago • 7 comments

A program I use in one of my workflows (https://github.com/autopkg/autopkg) depends heavily on reading/writing extended attributes/xattrs for determining whether to download remote files or use locally cached versions. When these attributes are missing, the program downloads new files, even if the files exist locally.

It looks like the flag --xattrs works on both the GNU and FreeBSD implementations of tar. https://www.gnu.org/software/tar/manual/html_node/Extended-File-Attributes.html https://www.freebsd.org/cgi/man.cgi?query=bsdtar&sektion=1&format=html

Is there any chance a fix would be as simple as adding that flag to dist/save/index.js?

williamtheaker avatar Mar 25 '22 15:03 williamtheaker

This issue is stale because it has been open for 200 days with no activity. Leave a comment to avoid closing this issue in 5 days.

github-actions[bot] avatar Apr 03 '23 08:04 github-actions[bot]

I'm still interested in this. I tried forking actions/cache to add xattr support without success:

/usr/local/bin/gtar --posix --use-compress-program zstd -T0 -cf cache.tzst --exclude cache.tzst -P -C /Users/runner/work/repo/repo --files-from manifest.txt --delay-directory-restore --xattrs
/usr/local/bin/gtar: XATTR support is not available

Looking at the source code for GNU tar, I don't really see why this is happening, but can reproduce the error when installing tar from homebrew on macOS. https://git.savannah.gnu.org/cgit/tar.git/tree/src/xattrs.c?h=release_1_34#n473

williamtheaker avatar Apr 03 '23 14:04 williamtheaker

+1 for interest in this.

Tried to tweak build settings to add support for extended attributes in gnu-tar using homebrew, but it appears to be missing some header files / developer library as well. Asking for support with this in Homebrew forum.

gnutar in MacPorts has the same issue.

codeskipper avatar Apr 09 '23 12:04 codeskipper

Pardon my ignorance, but while GNU tar (on macOS) is missing support for extended attributes, would using the tar version included in macOS be an option?

The macOS version of tar has an option --mac-metadata which is set by default that includes extended attributes in archives and extracts them as well (unless run as root).

As an example, I just downloaded a Firefox installer and it has some extended attributes:

ls -@alh ~/Downloads/Firefox\ 111.0.1.dmg
-rw-r--r--@ 1 mart  staff   127M Apr  9 14:02 /Users/mart/Downloads/Firefox 111.0.1.dmg
	com.apple.macl	  72B
	com.apple.metadata:kMDItemDownloadedDate	  53B
	com.apple.metadata:kMDItemWhereFroms	 179B
	com.apple.quarantine	  57B

An archive that includes the extended attributes can be created (with redundant default setting --mac-metadata) like:

/usr/bin/tar --mac-metadata -cvf test.tar ~/Downloads/Firefox\ 111.0.1.dmg
tar: Removing leading '/' from member names
a Users/mart/Downloads/Firefox 111.0.1.dmg

...and extracted again like so:

/usr/bin/tar --mac-metadata -xvf test.tar 
x Users/mart/Downloads/Firefox 111.0.1.dmg

...and verify presence of metadata:

mart@Martinus-MBP Downloads % ls -@alh ~/Downloads/Users/mart/Downloads/Firefox\ 111.0.1.dmg
-rw-r--r--@ 1 mart  staff   127M Apr  9 14:02 /Users/mart/Downloads/Users/mart/Downloads/Firefox 111.0.1.dmg
	com.apple.macl	  72B
	com.apple.metadata:kMDItemDownloadedDate	  53B
	com.apple.metadata:kMDItemWhereFroms	 179B
	com.apple.quarantine	  57B

codeskipper avatar Apr 09 '23 13:04 codeskipper

After looking a bit more at the switch in actions/cache to GNU tar away from BSD tar in this PR I decided to test if we can use BSD tar better for this use case.

A crude hack to revert to BSD by uninstalling GNU tar with Homebrew in a workflow allows us to use the macOS built-in BSD tar instead.

A test workflow shows this workaround succeeds in caching and restoring an example extended attribute we put there.

Note to self - when testing with this workflow, remember to delete the existing cache before switching from GNU tar to BSD or vice versa.

If this turns out to be a viable solution, I propose adding a boolean setting for whether to use GNU tar could be implemented for actions/cache. For clarity, I'd also propose adding argument --mac-metadata for BSD tar on macOS explicitly, the above workaround succeeds just because this is the default setting.

codeskipper avatar Apr 12 '23 07:04 codeskipper

This issue is stale because it has been open for 200 days with no activity. Leave a comment to avoid closing this issue in 5 days.

github-actions[bot] avatar Oct 29 '23 08:10 github-actions[bot]

I'm still interested in this. I'd create a PR to add a boolean setting for whether to use either native BSD tar or GNU tar for actions/cache, but I haven't learned TypeScript.

codeskipper avatar Oct 29 '23 11:10 codeskipper

This issue is stale because it has been open for 200 days with no activity. Leave a comment to avoid closing this issue in 5 days.

github-actions[bot] avatar May 17 '24 08:05 github-actions[bot]

This issue was closed because it has been inactive for 5 days since being marked as stale.

github-actions[bot] avatar May 22 '24 08:05 github-actions[bot]