pax substitution and relative symbolic links

Submitted by dag on Fri, 2012/06/08 - 19:46

When using pax -s to rewrite archived files on the fly, it also rewrites the symlink reference even if these symlinks are relative. This is highly unexpected, not documented and incorrect behavior.

Imagine you the following two files:

bin/test
sbin/test -> ../bin/test

If you would archive this using:

find . | pax -d -w -x ustar -s ',^,foo-1.2/,' >foo-1.2.tar

You end up with the following files in the archive:

foo-1.2/bin/test
foo-1.2/sbin/test -> foo-1.2/../bin/test

Which obviously is _never_ the correct behavior. For a relative path it should not perform any substitution.

A workaround in this case, is making use of the fact that pax will only do one successful substitution:

find . | pax -d -w -x ustar -s ',^\.,\.,' -s ',^,foo-1.2/,' >foo-1.2.tar

So we first match all the stuff we don't want to substitute, and substitute it by itself. (duh!) And then we do the substitution we want for all other cases.

perhaps you meant something

perhaps you meant something like

find . | pax -d -w -x ustar -s ',^\.\.,..,' -s ',^,foo-1.2/,' > /tmp/foo-1.2.tar

instead? otherwise the substitution is inhibited on all names, because they all start with './'.