[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-tar] compress list of files, when root folder is a symlink
From: |
Reuti |
Subject: |
Re: [Help-tar] compress list of files, when root folder is a symlink |
Date: |
Fri, 24 May 2019 20:15:26 +0200 |
Hi,
> Am 24.05.2019 um 19:58 schrieb Sergey Poznyakoff <address@hidden>:
>
> Hi,
>
>> ln -s /tmp/test/subfolder/dummyfile /tmp/test/subfolder/dummyfile-symlink
>> cd /tmp/test/
>> find ./subfolder-symlink/ > files.txt
>
> There are several problems with the archive created this way. First of
> all, it does not contain the entry for the directory subfolder-symlink
In my opinion it does have this entry:
$ tar tf corrupted-tar.tar.gz
./subfolder-symlink
./subfolder-symlink/dummyfile
./subfolder-symlink/dummyfile-symlink
> points to (that's the reason of the first error during extraction).
> Secondly, symbolic links refer to absolute path names. So, if you use
> the -P option while extracting:
>
> tar -Pzxvf corrupted-tar.tar.gz
>
> then it will extract fine, provided that the target directory exist.
Indeed, this works, even when the symlink to the target directory does not
exist beforehand.
===
But the behavior I found is still puzzeling: why does a two-stage extraction
work? `tar` seems to remember, that the subfolder-symlink is a symlink also for
later files in the archive and refuses further processing. While removing this
entry from the file list it will just process them as they are in the second
round.
-- Reuti
> But
> that's probably not what you want.
>
> The proper way to create the archive in this case would be to (1) add
> the subfolder entry to files.txt, (2) to use the --no-recursion option
> to avoid descending into it and (3) to transform absolute links to
> relative ones. E.g.:
>
> basename $(readlink ./subfolder-symlink) > files.txt
> find ./subfolder-symlink/ >> files.txt
> tar --no-recursion --transform 's|/tmp/test/||' \
> -S -c -T files.txt -zf uncompress-folder/corrupted-tar.tar.gz
>
> Regards,
> Sergey
>
>