0

I want to create an archive file that preserves the absolute path information of the originals, but I have not been able to find a way to do this that does not result in a tarbomb?

For concreteness, suppose that I want to make a (compressed) archive file (*.zip or *.tgz or anything else) that includes the files

/usr/share/foo/bsd/config.yaml
/usr/share/foo/linux/config.yaml
/usr/share/foo/windows/config.yaml

...and I want to preserve the information encoded in the full path of the original files.

Ideally, when the archive is extracted, it should produce the following files

./<BASENAME>/usr/share/foo/bsd/config.yaml
./<BASENAME>/usr/share/foo/linux/config.yaml
./<BASENAME>/usr/share/foo/windows/config.yaml

...where <BASENAME> stands for the archive file's basename (EXcluding its extension).

One way I could do this would be to create ./<BASENAME>/usr/share/foo/{bsd,linux,windows} directories, create symlinks in these directories to the corresponding files, create an archive of the ./<BASENAME> directory (including whatever flag may be needed to ensure that the symlinks get dereferenced at the time of adding items to the archive), and run rm -rf ./<BASENAME> once the archive file is ready.

Is there a less labored approach?

2 Answers 2

2

My approach would be similar to the following:

tar -Pczvf ./test.tgz /usr/share/foo/{bsd,linux,windows}

Using GNU TAR:
-P: absolute names
-c: create
-z: gzip compression
-v: verbose output
-f: file name for archive

This would give you a compressed archive with the absolute paths for the included files. Then you could extract the archive onto any base you would like using -C, or just extract the files to the absolute locations by using -P again:

tar -xzvf ./test.tgz -C $BASENAME
tar -Pxzvf ./test.tgz

0

You can try by using relative paths, something like:

cd /
tar cvf path/to/tar_file.tar usr/share/foo/{bsd,linux,windows}/config.yaml

so you have the path w/o leading slash.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.