Description
TL;DR: "The nice thing about standards is that you have so many to choose from." -Andrew S. Tanenbaum
I imported a template as a tar file from my MacOS desktop. The tar file seemed to upload without issue and the template was built/deployed just fine. Things went off the rails when I tried to edit it...
create file "/home/coder/.cache/coder/provisioner-0/work/PaxHeader/currentdir" (mode -rwxr-xr-x): open /home/coder/.cache/coder/provisioner-0/work/PaxHeader/currentdir: no such file or directory
Some spelunking led me on a spiritual journey of tar
Nobody is innocent here so I will start with FreeBSD. MacOS is it's more stylish cousin and as such inherited its tar(1)
implementation. Unlike GNU, FreeBSD likes to take the moral high road and thus decided to use the POSIX.1-2001/PAX for its tar implementation. Unfortunately for them the Open Group would rather see the world burn than break any sort of interoperability with some dead UNIX from the 80s so pretty much every fallback scenario parses the record as just another file. Next we have the authors of archive/tar
. They hate other people's things and decided to rewrite their tar implementation from scratch and have not yet realized the hell they stepped into. Then there is me. I hate all nice things and decided to use as complicated of a setup as I can muster. Finally, we have the coder team. They desperately would like to have nice things.
Unfortunately for them everyone in this story is conspiring against them. My desktop is joined to Active Directory so my UID is above 2097151. The libarchive devs are considerate about how they generate tar files in that they try to keep the output as universally portable as possible. (Do not confuse portable with compatible.) So, if the file that is being archived can be supported by basic ustar they will use that, otherwise they will bump up to PAX headers. Once you enter the land of PAX though, things get complicated. We are talking k-drama level complication. If you look at the ~500 lines of if/else statements you can get a taste for it if you don’t want to suffer through a season of 'Boys Over Flowers'. I think a tar file with PAX headers confuses something in the chain (possibly in mergePax) because PAX headers are completely valid files if you don't see them coming. When you view the template in the source you see this:
For reference GNU tar produces this:
Strangely though when I looked at archive.go it shouldn't care because it would have written the file on untar, or never looked for it on tar. With this, I realized enlightenment was unattainable and decided to just rant my findings here.
The only constructive ideas I could come up with on how to address this. Wrap libarchive
or one of the other complete implementations. Have the authors of archive/tar
handle that header since it looks like they explicitly hardcode some other popular PAX headers. Ignore any directory name that starts with PaxHeader
. Document that the tar format should be in ustar
when using MacOS. Or just ban me from computers so the coder team can have one less reason we can’t have nice things.