GNU tar `--one-top-level` now gives "Invalid cross-device link" error
To extract an archive at a certain location (which may not exist yet), I like to use the --one-top-level option, e.g.
tar xzf ARCHIVE.tar.gz --one-top-level=/my/folder
This has always worked fine, but recently (looking at logs of docker build actions) it just produces errors:
tar: /my/folder: Cannot mkdir: Invalid cross-device link
tar: /my/folder/somefile: Cannot open: Invalid cross-device link
I can reproduce the error on my WSL installation, so it doesn't seem to be specific to the environment where I build docker containers. It started happening on July 7th, and happens Ubuntu 22.04, 24.04 and 26.04.
Did something change to tar or the one-top-level option? Currently running version `1.35+dfsg-4ubuntu0.4` on my WSL installation which is affected.
Top Answer/Comment:
The problem doesn't occur only in Ubuntu. I recently stumbled upon it in a totally different Linux distribution (Red Hat). After update of the tar package, tar started to report "Invalid cross-device link" when extracting archive to a directory that has symlinks to subdirectories that are outside the extract dir (even without --one-top-level, just with -C parameter specifying the target dir). This layout is intentional, and the tar archive was built so that it contained files from all those symlinked subdirectories.
This has worked literally for years and just recently started to throw this error.
I did some tracing with strace on old and new tar and found out that there was a recent change in tar that made it use openat2() system call which previous versions didn't use, and that call is what fails and reports "invalid cross-device link".
In my opinion it's a compatibility breaking change and I'm very disappointed that tar developers decided to do this. As for now, the only workaround I can suggest is - roll back the tar package to the last working version and prevent it from upgrading. You can do this by selecting tar package in Synaptic, and then choosing "Package" -> "Lock version" from the menu. Packages marked this way will not be upgraded.
상단 광고의 [X] 버튼을 누르면 내용이 보입니다