在 Windows 上提取 Tarball 的符号链接问题

在 Windows 上提取 Tarball 的符号链接问题

我在提取时遇到问题这个压缩包(直接链接)在 Windows 平台上。问题是 tarball 包含符号链接和Windows 平台(我在 Windows 平台上拥有的 tar 实用程序)不知道如何处理它们。

我在MSYS2/MinGW-w64环境。提取档案会导致以下错误消息:

$ tar -xf SDL2_mixer-2.0.4.tar.gz
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/OpusFile.framework/Resources: Cannot create symlink to ‘Versions/Current/Resources’: No such file or directory

tar: SDL2_mixer-2.0.4/Xcode/Frameworks/OpusFile.framework/Headers: Cannot create symlink to ‘Versions/Current/Headers’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/OpusFile.framework/OpusFile: Cannot create symlink to ‘Versions/Current/OpusFile’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/Vorbis.framework/Vorbis: Cannot create symlink to ‘Versions/Current/Vorbis’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/Vorbis.framework/Resources: Cannot create symlink to ‘Versions/Current/Resources’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/Vorbis.framework/Headers: Cannot create symlink to ‘Versions/Current/Headers’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/Ogg.framework/Ogg: Cannot create symlink to ‘Versions/Current/Ogg’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/Ogg.framework/Resources: Cannot create symlink to ‘Versions/Current/Resources’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/Ogg.framework/Headers: Cannot create symlink to ‘Versions/Current/Headers’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/modplug.framework/modplug: Cannot create symlink to ‘Versions/Current/modplug’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/modplug.framework/Resources: Cannot create symlink to ‘Versions/Current/Resources’: No such file or directory tar: SDL2_mixer-2.0.4/Xcode/Frameworks/modplug.framework/Headers: Cannot create symlink to ‘Versions/Current/Headers’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/mpg123.framework/mpg123: Cannot create symlink to ‘Versions/Current/mpg123’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/mpg123.framework/Resources: Cannot create symlink to ‘Versions/Current/Resources’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/mpg123.framework/Headers: Cannot create symlink to ‘Versions/Current/Headers’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/FLAC.framework/Resources: Cannot create symlink to ‘Versions/Current/Resources’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/FLAC.framework/FLAC: Cannot create symlink to ‘Versions/Current/FLAC’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/FLAC.framework/Headers: Cannot create symlink to ‘Versions/Current/Headers’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/Opus.framework/Opus: Cannot create symlink to ‘Versions/Current/Opus’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/Opus.framework/Resources: Cannot create symlink to ‘Versions/Current/Resources’: No such file or directory
tar: SDL2_mixer-2.0.4/Xcode/Frameworks/Opus.framework/Headers: Cannot create symlink to ‘Versions/Current/Headers’: No such file or directory
tar: Exiting with failure status due to previous errors

$ echo $?
2

因为我在脚本中使用此命令,所以tar命令的返回值决定了脚本是否应在失败时退出。

tar -xf SDL2_mixer-2.0.4.tar.gz
RET=$?
if test ${RET} -ne 0; then
    echo "An error occurred during extraction. Exiting ..."
    exit ${RET}
fi

GNU Tar 有-h|--dereference开关,但这仅用于压缩,而不是提取。

我目前可以通过使用以下命令排除“Xcode”目录(我相信它只在 MacOS 上使用)来解决该问题:

$ tar --exclude="SDL2_mixer-2.0.4/Xcode" -xf SDL2_mixer-2.0.4.tar.gz

但是如果有办法保持“Xcode”目录完整并将符号链接转换为常规文件,我愿意这样做。

使用 7zip 解压 tarball 时我收到类似的错误:

$ "/c/Program Files/7-Zip/7z.exe" x -y SDL2_mixer-2.0.4.tar.gz
...

$ "/c/Program Files/7-Zip/7z.exe" x -y SDL2_mixer-2.0.4.tar
...
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\OpusFile.framework\Resources
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\OpusFile.framework\Headers
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\OpusFile.framework\OpusFile
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\OpusFile.framework\Versions\Current
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Vorbis.framework\Vorbis
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Vorbis.framework\Resources
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Vorbis.framework\Headers
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Vorbis.framework\Versions\Current
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Ogg.framework\Ogg
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Ogg.framework\Resources
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Ogg.framework\Headers
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Ogg.framework\Versions\Current
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\modplug.framework\modplug
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\modplug.framework\Resources
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\modplug.framework\Headers
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\modplug.framework\Versions\Current
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\mpg123.framework\mpg123
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\mpg123.framework\Resources
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\mpg123.framework\Headers
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\mpg123.framework\Versions\Current
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\FLAC.framework\Resources
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\FLAC.framework\FLAC
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\FLAC.framework\Headers
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\FLAC.framework\Versions\Current
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Opus.framework\Opus
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Opus.framework\Resources
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Opus.framework\Headers
ERROR: Can not create symbolic link : A required privilege is not held by the client. : .\SDL2_mixer-2.0.4\Xcode\Frameworks\Opus.framework\Versions\Current
...

有一个替代 zip 档案(直接链接)我可以使用它来代替,但 tarball 在非 Windows 平台上非常常见,我想学习如何解决这个问题以供将来参考。

更新:2022-06-18

来自jigwan 的回答Eric Gopak 的评论:看来 7-zip 可以使用内置 Windowsmklink命令来处理符号链接的转换。但是,mklink这需要提升权限或在 Windows 系统上启用开发人员模式。对于没有管理权限的用户来说,这可能不是一个可行的解决方案。

答案1

Windows 可以很好地处理符号链接(请参阅链接命令)。当我尝试在 Windows 10 上使用 GNU tar 进行提取时,也遇到了同样的问题。但是,如果我以管理员身份运行终端(或以管理员身份运行 7-Zip GUI),7-Zip 可以很好地处理它。

$ /c/Program\ Files/7-Zip/7z.exe x SDL2_mixer-2.0.4.tar.gz
...

$ /c/Program\ Files/7-Zip/7z.exe x -oSDL2_mixer_7z/ SDL2_mixer-2.0.4.tar

7-Zip 18.06 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2018-12-30

Scanning the drive for archives:
1 file, 45209600 bytes (44 MiB)

Extracting archive: SDL2_mixer-2.0.4.tar
--
Path = SDL2_mixer-2.0.4.tar
Type = tar
Physical Size = 45209600
Headers Size = 1409536
Code Page = UTF-8

Everything is Ok

Folders: 283
Files: 2432
Size:       43182017
Compressed: 45209600

相关内容