Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Apr 2018 06:30:05 +0200
From:      Polytropon <freebsd@edvax.de>
To:        freebsd@dreamchaser.org
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: tar xf foo -- how to restore symlink?
Message-ID:  <20180418063005.056e321d.freebsd@edvax.de>
In-Reply-To: <5ff313cf-6148-be90-0195-7d21f1f836ac@dreamchaser.org>
References:  <5ff313cf-6148-be90-0195-7d21f1f836ac@dreamchaser.org>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On Tue, 17 Apr 2018 22:20:23 -0600, Gary Aitken wrote:
> I've got a tarball with an archived symlink and its contents.
> The symlink points to another directory in the tarball, and the
> tarball contains copies of the files in the symlinked directory.
> 
> A normal extract fails with the message:
> $ tar -xf nufraw-0.41.tar.gz
> nufraw-0.41/doc-pak: Can't replace existing directory with non-directory
> 
> What's the right way to deal with this?
> 
> How do I get tar to restore the symlink as a symlink?
>    -k and --exclude allow tar to continue unpacking,
>    but don't restore the symlink as such.
> 
> "man tar" doesn't seem to have what I want but I'm probably blind.

Have you checked if -P or -U result in the intended behaviour?

     -P, --absolute-paths
             Preserve pathnames.  By default, absolute pathnames (those that
             begin with a / character) have the leading slash removed both
             when creating archives and extracting from them.  Also, tar will
             refuse to extract archive entries whose pathnames contain .. or
             whose target directory would be altered by a symlink.  This
             option suppresses these behaviors.

     -U, --unlink, --unlink-first
             (x mode only) Unlink files before creating them.  This can be a
             minor performance optimization if most files already exist, but
             can make things slower if most files do not already exist.  This
             flag also causes tar to remove intervening directory symlinks
             instead of reporting an error.  See the SECURITY section below
             for more details.

Check "man tar" for "symlink". :-)



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20180418063005.056e321d.freebsd>