7 ms·
Tar Files Created on macOS Display Errors When Extracting on Linux (2024)
- LatencyKills 6mo agoEx-Apple engineer here. This is, for better or worse, just the way Apple approaches this type of problem. From Apple's perspective, this is the way to preserve Finder / Gatekeeper / metadata semantics. It avoids silent data loss when round-tripping archives between Macs. This behavior also maintains consistency with copyfile(3) (as well as the Archive Utility behavior). Apple treats tar less like “portable Unix interchange” and more like “archive this filesystem object faithfully.” That is very Apple, and very libarchive. ;-) This is probably going to get worse (as Apple continues to add macOS-specific metadata), so your workaround is very helpful. I haven't tested it in a while, but at one point, setting the COPYFILE_DISABLE=1 env variable would disable the inclusion of macOS-specific metadata.
- Terretta 6mo agoArguably, principle of least surprise is very Apple. If I point "tape archive" at a file system, I want that file system archived to tape. And so, tar does. If I don't, well, that's a fine option, and there's a fine option for that. So it's less of a "workaround" or something that "gets worse", than, "No, I don't really want a tape archive of this filesystem, only of some of it." And that's supported. That said, never seeing another .DS_Store should be a system-wide option!
- taftster 6mo ago> That said, never seeing another .DS_Store should be a system-wide option! Yes please.
- ryandrake 6mo ago.DS_Store, .fseventsd, .Spotlight-V100, .Trashes, and ._this and ._that These can all die in a fire too, as far as I am concerned. macOS loves to treat the user's filesystem as its own personal garbage dump.
- gerdesj 6mo agothumbs.db and those weird MS alternative stream files for recording origination. filesystem attributes are for decorating files with meaning. Anything else that attempts to use filesystems in "interesting" ways is silly. Apple and MS really ought to consider why they do this sort of fragile, idiosyncratic nonsense.
- Joker_vD 6mo agoBut... thumbs.db is precisely not an "attempt to use filesystems in "interesting" ways" — it's literally a just hidden file with previews stored in it. Storing the preview in the alternative stream of the file with the picture itself would be "an interesting way".
- kstrauser 6mo agoAgreed. Where else would you put that stuff? It’s gotta go somewhere, and this is the least surprising place IMO. Anywhere else would have to be a parallel store that follows filesystem mounts and unmounts, renaming directories, etc so that it alway perfectly mirrors the thing it’s configuring.
- noisem4ker 6mo ago> Where else would you put that stuff? A "Centralized thumbnail cache" in the user profile folder, where it's been for a long while. https://en.wikipedia.org/wiki/Windows_thumbnail_cache https://en.wikipedia.org/wiki/Windows_thumbnail_cache > so that it alway perfectly mirrors Who cares? It's a cache.
- kstrauser 6mo agoThat windows takes an approach does not mean it’s a good idea. And what about things like folder settings, such as whether to display is as a list or as icons, or how to sort it, etc? That’s more important than a thumbnail cache.
- 6mo ago
- JoshTriplett 6mo ago> Arguably, principle of least surprise is very Apple. Principle of least surprise is good engineering practice. The question is always whose surprise. Someone who expects tar to behave like other UNIX systems is going to be surprised by this. Someone who expects tar on Apple to have perfect fidelity would be surprised by not-this. I increasingly feel like build systems should never be relying on any "native" utilities from the host system, and should instead be bringing them in via dependencies. You can't have this problem if your packaging system pulls in a specific portable `tar` library.
- amarant 6mo agoNixos has a pretty solid solution to this issue: key your dependencies with checksums of the content. That way you get the best of both worlds: you always get the exact version you want, and you can share a copy of that exact version with other software that wants to use that exact version too!
- JoshTriplett 6mo agoYeah, Nix-like distributions (e.g. guix, lix) do for Linux systems what some language package managers (e.g. cargo) do for individual projects.
- altairprime 6mo agoAre the xattr / chattr / umask checksums rolled into the main data fork content or are they hashed separately (or not at all)?
- a_t48 6mo agoIIRC Nix is checksummed in the hash of the source of the content, not the results.
- microtonal 6mo agoHash of a normalization of the derivation, so this roughly means source, dependencies and the ‘build recipe’. The exception are fixed-output derivations, which are typically content-hashed. That said, a lot of work is done in content-addressed hashing, but AFAIK it’s not the default yet.
- saghm 6mo agoIf you think that most people who run the tar command are assuming it will work like a tape archive, you'll probably be the one surprised
- adrian_b 6mo ago> I want that file system archived to tape. And so, tar does. The traditional UNIX tar and cpio utilities cannot archive the modern Linux file systems without loss of metadata. Most modern tar programs implement various file format extensions as a workaround for this, but the extensions may be incompatible between distinct tar programs and frequently they are very poorly documented. Some years in the past, libarchive was the only archiver available on Linux that guaranteed lossless backups for the Linux file systems, e.g. xfs or ext4 (and also lossless file transfers between Linux file systems and FreeBSD file systems). Therefore that is what I have been using on Linux since then. Presumably since then GNU tar and other tar programs should have caught up with it, but I have not verified this. Whichever tar program was used in TFA, it was an obsolete tar program, and that was the real problem, not that the archives had been created on an Apple computer.
- matheusmoreira 6mo agoIt's a good attitude to have, in my opinion. Portability is overrated. Linux developers should be doing a lot more of this. We should be making everything work better for us without caring how it's going to impact other irrelevant platforms. Let the people who actually care about those platforms worry about such things.
- cozzyd 6mo agoIt would at least be nice if there was a way to keep apple users from shitting all over the filesystem with remote mounts and ds_store files. Perhaps by automatically unmounting if one is detected.
- bombcar 6mo agoAt least if you're using ZFS as the backing store and Samba, you can set vfs objects = catia fruit streams_xattr and similar config options to use extended attributes.
- seqastian 6mo agodefaults write com.apple.desktopservices DSDontWriteNetworkStores true
- Maskawanian 6mo agoAt least with Samba you can use the "veto files" and "delete veto files" global directives to deal with those, I personally use the following for veto files: /._*/.AppleDB/.AppleDouble/.AppleDesktop/:2eDS_Store/Network Trash Folder/Temporary Items/TheVolumeSettingsFolder/.@__thumb/.@__desc/:2e*/.@__qini/.Qsync/.@upload_cache/.qsync/.qsync_sn/.@qsys/.digest/ I understand that I may loose resource forks, but that isn't a problem for the use case of my server.
- cozzyd 6mo agounfortunately this is mostly people ssh mounting. I think I can probably write a ebpf rule to avoid writing them though. Or disconnect their sessions. Or modify the .DS_Store to change the finder background to something amusing.
- jmclnx 6mo agoTo me, the big question is why Apple needs all these file attribute ? If the files are extracted OK, just ignore the errors :)
- bombcar 6mo agoApple has had multiple streams per file since the very beginning, and it can store useful and necessary information (the latter is quite rare now, as most things have sane defaults, but losing the extended attributes can lose things that can be annoying).
- hamasho 6mo agoFunnily enough, I got the error message and asked Claude Code, and it replied; The warning can be suppressed by `--no-xattrs --no-mac-metadata`. then just edited the code as - tar czf dist.tar.gz dist + COPYFILE_DISABLE=1 tar czf dist.tar.gz dist
- adrian_b 6mo agoYes, I completely disagree with TFA. The problem described in TFA is not specific to Apple, but the same problem appears when archiving any decent filesystem that has been designed during the last 3 decades and not a half of century ago, including all Linux file systems. The problem described in TFA is not caused by Apple, but by the author using an obsolete tar program and not being aware of this. The traditional tar file format cannot store a lot of the metadata that is contained in modern file systems (e.g. high resolution timestamps, access control lists, extended file attributes), so it is useless for such file systems. Most modern "tar" implementations have added extensions to the tar file format, to make it usable with modern file systems, such as Linux XFS or Linux EXT4. But many of these extensions are incompatible between themselves, so certain tar files can be fully extracted only with the same tar program that has created them. I strongly recommend against using the old tar or cpio file formats. Even with various extensions it is not guaranteed that they always work correctly. I always use only the pax file format, which has also required extensions in order to work with the modern file systems, but the pax extensions are cleaner than those for tar, because the file format is better designed. Libarchive, which was mentioned in TFA, is available in most Linux distributions or it can be built from source on any Linux computer. It provides an executable that is preferable to tar (better invoked as "bsdtar --format=pax") for the backup or transfer of any Linux files. I have not checked recently GNU tar or other tar programs available on Linux, and I hope that meanwhile they have been upgraded to be able to archive losslessly the Linux file systems, but some years ago that was not true, so using tar or cpio on Linux could easily corrupt the archived files.
- deleted 6mo ago[deleted]
- pier25 6mo agoI use these settings when creating a tar file for deploy: tar --no-xattrs --no-mac-metadata -czf
- jherskovic 6mo agoI do this same thing too when building archives in macOS I will unpack on Linux later.
- bestony 6mo agoThanks for the command! I'll try using it to package next time.
- firesteelrain 6mo agoYou can either send stderr to /dev/null or use --warning=no-unknown-keyword to suppress them cleanly. But still interesting nonetheless why they are added
- angry_octet 6mo agoWe might also ask, why doesn't Linux also track such meta-data? Are Linux users not also subject to drive-by downloads impersonating valid files? Should we be one chmod a+x away from compromise?
- danielheath 6mo agoYes, we should be. My computer should run programs when I tell it to run them. Don’t blunt _every_ tool just to make them harder to cut yourself on.
- angry_octet 6mo agoI hope you're in the very small minority of people who rigorously manage untrusted downloads and whitelist every binary, because you're operating an appliance from the 1970s, sticking a metal fork into an un-earthed toaster. Most people need help from their operating system.
- b65e8bee43c2ed0 6mo agothen we, the very small minority, want a button to disable that help.
- Joker_vD 6mo agoI sincerely agree. By the way, thanks for lending your machine for my "Network-Retransmission-and-Compute-as-a-service" network.
- rtpg 6mo agoIncreased metadata isn't tool blunting in itself though, even if MacOS uses it for being... annoying is one way of saying it. Provenance information bundled into a file is not the worst idea in the world IMO. We have created/modified timestamps on files already, right? There's definitely the question of "why" but hey if more of my binaries just had at least a tag about who put them there that would be a win in my book. Not an argument for doing what MacOS does, just an argument that the info would be nice to have.
- chmaynard 6mo agoHomebrew installs GNU tar as "gtar". On my M4 MacBook: $ which gtar gtar is /opt/homebrew/bin/gtar
- fastily 6mo agoIve installed the gtar formula and aliased it to tar. Cant be bothered to memorize the differences between macOS tar and unix tar, especially when the latter is considered to be the de facto standard
- jen20 6mo ago> and unix tar It's in the name: GNU's Not Unix.
- FearNotDaniel 6mo agoBut, ironically enough, MacOS _is_ Unix: https://www.opengroup.org/openbrand/register/ https://www.opengroup.org/openbrand/register/
- throw0101a 6mo agoPer this 2018 page, GNU tar seems to work with SCHILY.* encoded xattrs, but not LIBARCHIVE.* ones: * https://mgorny.pl/articles/portability-of-tar-features.html#generic-extended-attributes https://mgorny.pl/articles/portability-of-tar-features.html#... * Via: https://github.com/mxmlnkn/ratarmount/issues/145 https://github.com/mxmlnkn/ratarmount/issues/145 bsdtar ≥3.7.2 apparently adds both types to its files for maximum portability: * https://github.com/libarchive/libarchive/pull/691/files#diff-dadc66d540d1d3dbe2364cc4e7c99e329b68e6830e467e594002f03864074231R146 https://github.com/libarchive/libarchive/pull/691/files#diff... AFAICT, bsdtar will default to "ustar" format, but will auto-switch to "pax" if needed.
- Pay08 6mo agoI wonder how come GNU tar never added them. I have to assume someone has brought the problem to their attention before.
- bombcar 6mo agoI'll admit that if I don't care about extended attributes (I never really do) I just use zip instead.
- chungy 6mo agoI have bad news for you: Zip supports storing extended attributes as well.
- seba_dos1 6mo ago> Why does it have those extra files? > For some reason Very informative!
- ktm5j 6mo agoThey aren't even files.. they're just file metadata called extended attributes. This problem has nothing to do with tar either, it's about differences between the OS filesystems. Really nothing to see here IMO.
- raffraffraff 6mo agoWould this ever affect me if I don't use many of MacOS built on tools? I brew install gnu equivalents make them all default. Just like how I also don't use most of their desktop environment stuff, and instead use rectangle, hammerspoon, karabiner to make it feel more like the Linux desktop I wish I could use at work.
- thomas_viaelo 6mo agoMostly yes. If `tar` resolves to gtar in your PATH, your archives won't carry the LIBARCHIVE.* xattrs that GNU tar can't decode, so the warnings go away. One thing that still trips me up though: `._Foo.txt` AppleDouble files get created in your filesystem any time something Finder-adjacent touches a folder, and gtar archives them just fine, but they show up as garbage on the Linux side. `dot_clean -m mydir/` before tarring kills them, or you can pipe through `--exclude='._*'` if you don't want to touch the source tree.
- anthk 6mo agoHow well does pax handle this?
- albertzeyer 6mo agoBut these are not errors. These are just warnings you can ignore? It's not really so critical?
- red_admiral 6mo agoWhy switch to a completely different tar and rewire the PATH when you could just set a shell alias? You'll need to edit .bashrc both times but there's no need to install a second tar to /opt to solve this.
- LoganDark 6mo ago> If you are using a Mac with an Apple Silicon M1, M2, M3 or M4 processor, Don't forget the MacBook Neo's A18 Pro :)
- nottorp 6mo agoI don't see errors, just warnings about unknown metadata. It's annoying yes. But they aren't errors.
- mxmlnkn 6mo agoThe title seems misleading. These are not errors. They are simply warnings about extended attributes being ignored when extracting files, which seems completely fine to me, and creating the tar without those extended attributes has exactly the same outcome, but throws away the metadata at archive time instead of extraction time. Furthermore, this is not an Apple/macOS issue. The tool used is bsdtar, so it would also affect all BSD-variants that default to bsdtar/libarchive, and those systems also have extended attributes, e.g., for SELinux, which would get added to the TAR.
- nomel 6mo agoIt's unfortunate there was never a standardization around how to print different "levels" of messages. Imagine how nice things could be if we had a standard system call for the equivalent of log level, early on!
- mg794613 6mo agoOh Arul John, just because you don't understand, means it's a error. What horrible advice also to download different tar versions, for something that should just be explained properly. If it weren't for the "2024" in the title, I would have thought this to be a result from AI. But it's not artificial intelligence. It's real stupidity.
- kaiwn 6mo agoLet me google the name of the author of this blog... Oh...
- oomuinio 6mo ago[dead]
- crest 6mo ago[dead]
- Cockbrand 6mo agoI don't see the issue here. Some filesystems store data in several streams, and have been doing so for decades. GNU tar gives warnings about stuff it doesn't know, and which can be ignored without a problem. If you haven't ever seen a different *nix system than Linux, this may be a surprise, but it should be taken as an opportunity to learn something new and move on.
- ninefathom 6mo ago"For some reason" there are ._ files... now I'm really feeling old, that an apparently-savvy macOS user seems to be unaware of the history of resource forks and AppleDouble. That was fundamental knowledge in the subject of Mac/PC interchange not terribly long ago.
- ChiperSoft 6mo agoI remember when creating a zip file from the finder filled it with a bunch of resource fork files that confused the hell out of anyone opening it on windows.
- wolfi1 6mo agofun fact you don't need the hyphen. tar cvzf works also