Tar knows how to delay symlink creation, but uses that functionality sparingly (the source code is kind of convoluted, and also uses 8-char tabs, which doesn't help readability, so i wasn't able to discern when exactly it's used).
My enhancement request is for a mode in which tar would delay *all* links unconditionally if the target of the link does not exist. Then, once everything else is extracted, tar should do passes over the list of delayed link requests, trying to fulfill them, and only stop with an error (after an extra pass that would be needed to list all the links that can't be re-created) once it iterates over the list without creating any new symlinks. This feature would *greatly* improve tar usability on Windows (including Cygwin with winsymlinks:nativestrict option), since symlinks can't be created in a deterministic fashion if their target does not exist (because NTFS has separate symlinks for files and for directories, and mixing up the symlink type produces a symlink that does not function). There are alternative ways of tackling that problem, but most of them are restricted by POSIX compatibility - symlink() simply has no way for the caller to say that it knows what kind of symlink type (file or directory) should be created. So even if tar somehow manages to store symlink target type in the archive (as some sort of extension?), it still wouldn't be able to make use of that information. Though maybe there's a Cygwin-specific API that tar would be willing to use...hard to say, i haven't studied Cygwin source code that closely. Anyway, delayed symlinks are already a thing, so we might as well use them. I've tried to hack together a patch, but was ultimately unsuccessful. It mostly involved storing more state in the link list (since it's going to be around longer than normal, and its element wouldn't be destroyed during the first and the only pass), overriding the decision about creating placeholders (also, re-creation of placeholders when one is unlinked prior to creation of a link, and then the link creation fails... though maybe that's an overkill, i was never clear on why placeholders were needed in the first place), and adding an external while() loop around delayed symlinking code. Also, handled (re-created) sources have to be marked somehow (turn them into 0-length strings? stringlist is difficult to hack on). The whole thing came crashing down, and debugging under Cygwin is a PITA, so i gave up. P.S. Also, such mode might be useful in other cases as well. For example, it could be desirable to extract all the files that *are* in the archive, and tar barfing out after that with a list of symlinks it couldn't recreate might be an acceptable outcome.
signature.asc
Description: OpenPGP digital signature