Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symlinks fail to extract in tar #1216

Open
jeroen opened this issue Apr 6, 2018 · 9 comments
Open

Symlinks fail to extract in tar #1216

jeroen opened this issue Apr 6, 2018 · 9 comments

Comments

@jeroen
Copy link
Contributor

jeroen commented Apr 6, 2018

Consider the following example:

curl -OL https://cran.r-project.org/src/base/R-3/R-3.4.4.tar.gz
tar -xf R-3.4.4.tar.gz

This command fails in msys2. The reason is that the archive contains symlinks, but within the archive the symlink appears before the actual file that it links to. Therefore tar fails to resolve the link on-the-fly because it can't link to something that isn't there yet.

The issue here is that the R-3.4.4.tar.gz file was created on macOS (with bsdtar) which does not have a --sort option. Hence random ordering of files within a tar is not illegal and very common.

A workaround is the following:

set MSYS=winsymlinks:lnk
tar -xf R-3.4.4.tar.gz

This will replace symlinks in the tar archive by windows shortcuts instead of trying to resolving them on the fly.

It took me two days to find this solution. Perhaps MSYS=winsymlinks:lnk should be the default in tar like it is in Cygwin? Or alternatively tar should be modified to first extract real files before extracting symlinks.

@jeroen
Copy link
Contributor Author

jeroen commented Apr 6, 2018

Interestingly this issue seems the opposite of #140. Has the default value for winsymlinks changed in the mean while?

@mingwandroid
Copy link
Member

The default should be whatever works best on the given system (do when supported, native symlinks).

lnk files go not work with the standard C library functions on Windows unfortunately. The are interpreted 'correctly' by Cygwin and Windows explorer only.

@angelog0
Copy link

angelog0 commented Apr 7, 2018

@jeroen wrote:

A workaround is the following:

set MSYS=winsymlinks:lnk
tar -xf R-3.4.4.tar.gz

..another workaround is to run tar two times:

tar -xf R-3.4.4.tar.gz    # Now it prints errors...
tar -xf R-3.4.4.tar.gz    # Now all is fine...

FlyingWombat added a commit to FlyingWombat/MSYS2-packages that referenced this issue Jan 30, 2020
extraction with bsdtar wasn't working due to symlinks in the source.
Followed advice in github.com/msys2/issues/1216
and set MSYS="winsymlinks:lnk" in the environment.
The symlinks don't matter anyway, since I explicitly replace them with copies.
@alexjorgef
Copy link
Contributor

alexjorgef commented May 21, 2020

@jeroen wrote:

A workaround is the following:
set MSYS=winsymlinks:lnk
tar -xf R-3.4.4.tar.gz

..another workaround is to run tar two times:

tar -xf R-3.4.4.tar.gz    # Now it prints errors...
tar -xf R-3.4.4.tar.gz    # Now all is fine...

I think I'm experiencing something similar:

tar: ansible-2.9.7/lib/ansible/plugins/lookup/_openshift.py: Cannot create symlink to ‘k8s.py’: No such file or directory
tar: ansible-2.9.7/test/integration/targets/supervisorctl/tasks/install_Darwin.yml: Cannot create symlink to ‘install_pip.yml’: No such file or directory
...
tar: Exiting with failure status due to previous errors
==> ERROR: A failure occurred in prepare().

The next solution work for me, PKGBUILD prepare function:

...
prepare() {
  [[ -d ${pkgname}-${pkgver} ]] && rm -rf ${pkgname}-${pkgver}
  tar zxf "${srcdir}/${pkgname}-${pkgver}.tar.gz" || true
  tar zxf "${srcdir}/${pkgname}-${pkgver}.tar.gz"
}
...

And this errors occur on final steps of build:

...
warning: BuildScriptsCommand: bin/ansible-playbook is an empty file (skipping)
warning: BuildScriptsCommand: bin/ansible-pull is an empty file (skipping)
warning: BuildScriptsCommand: bin/ansible-doc is an empty file (skipping)
warning: BuildScriptsCommand: bin/ansible-galaxy is an empty file (skipping)
warning: BuildScriptsCommand: bin/ansible-console is an empty file (skipping)
copying and adjusting bin/ansible-connection -> build/scripts-3.8
warning: BuildScriptsCommand: bin/ansible-vault is an empty file (skipping)
warning: BuildScriptsCommand: bin/ansible-config is an empty file (skipping)
warning: BuildScriptsCommand: bin/ansible-inventory is an empty file (skipping)
copying and adjusting bin/ansible-test -> build/scripts-3.8
error: [Errno 2] No such file or directory: 'build/scripts-3.8/ansible-playbook'

Edit: After some builds, realize that BuildScriptsCommand need symlinks as shortcuts:

...
prepare() {
  [[ -d ${pkgname}-${pkgver} ]] && rm -rf ${pkgname}-${pkgver}
  tar zxf "${srcdir}/${pkgname}-${pkgver}.tar.gz" || true
  MSYS=winsymlinks:lnk tar zxf "${srcdir}/${pkgname}-${pkgver}.tar.gz"
}
...

@adgnaf
Copy link

adgnaf commented Dec 1, 2020

set MSYS=winsymlinks:lnk

is not work in my case.
I use

export MSYS=winsymlinks:lnk

instead.

@jonesbusy
Copy link

Same issue here

export MSYS=winsymlinks:lnk

workaround is working on my side

@betterpig
Copy link

set MSYS=winsymlinks:lnk
not work for me in windows.
run tar twice not work for me yet.

@Biswa96
Copy link
Member

Biswa96 commented Jan 5, 2022

As a workaround, try with ZIP file.

@alex-tee
Copy link

alex-tee commented Aug 9, 2023

could #3946 be related?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants