坑人的macos tar 下令 (现实上是bsdtar)换用 gnu tar

伤心客  金牌会员 | 2024-7-23 22:41:38 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 993|帖子 993|积分 2979

周末 看着条记本上好用的朗文当代高级词典(mac版)和别的两部词典,准备复制到黑苹果台式机上去。考虑到词典内容有太多小文件,普通复制传输太慢,毫无疑问用 tar 打包肯定快而且能保存原始文件的各种信息。下令如下:
  1. time tar czf ~/tmp/Diction.tgz ./LDOCE5.dictionary ./ccald.dictionary
复制代码
约莫3分钟左右结束,sftp 上传台式机。运行 解压下令:
  1. $ tar xf ~/Diction.tgz
  2. tar: Special header too large
  3. tar: Error exit delayed from previous errors.
复制代码
这什么意思?赶快在条记本上测试一遍,效果一样。用了这么多年Linux和macos 这是第一次碰到tar下令创建乐成 但解压却失败,假如这是备份关键文件,后果无法想象。网上搜刮了一下,看到下面的内容:
https://forums.freebsd.org/threads/tar-special-header-too-large-error.73612/
  1. tar: Special header too large error | The FreeBSD Forums
  2. Jan 8, 2020 · I'm piping a bzip2 compressed tar file into tar on FreeBSD 11.2-RELEASE and seeing this error. Anyone any idea what this may indicated? I suspect that after this
复制代码
嗯 对办理问题毫无用途,不过发现一点,这个应该是 bsdtar 出现的问题。
  1. $ ls -l `which tar`
  2. lrwxr-xr-x  1 root  wheel  6 Feb 26 13:47 /usr/bin/tar -> bsdtar
复制代码
去GNU官网 ​​​​​​https://ftp.gnu.org/gnu/tar/ 下载最新版 tar ,下令行编译:
  1. $ tar xf ~/Downloads/tar-1.35.tar.xz
  2. $ cd tar-1.35
  3. $ ./configure
  4. $ make
  5. .......
  6.   CC       xattrs.o
  7.   CCLD     tar
  8. Undefined symbols for architecture x86_64:
  9.   "_iconv", referenced from:
  10.       _utf8_convert in utf8.o
  11.   "_iconv_open", referenced from:
  12.       _utf8_convert in utf8.o
  13. ld: symbol(s) not found for architecture x86_64
  14. clang: error: linker command failed with exit code 1 (use -v to see invocation)
  15. make[2]: *** [tar] Error 1
  16. make[1]: *** [all-recursive] Error 1
  17. make: *** [all] Error 2
  18. make  35.08s user 11.97s system 90% cpu 52.118 total
复制代码
本以为是个简朴的库文件问题,效果搜刮半天毫无进展,花的时间可以直接传输几遍了,不过这么简朴的问题都办理不了,还怎么开发程序?终于下定决心,直接改Makefile,为保险起见,先添加 -v 参数到Link下令参数中:
  1. $ mvim src/Makefile
  2.   LDFLAGS = -v
  3. $ make
  4.   CCLD     tar
  5. Apple clang version 14.0.3 (clang-1403.0.22.14.1)
  6. Target: x86_64-apple-darwin21.6.0
  7. Thread model: posix
  8. InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
  9. "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -platform_version macos 12.0.0 13.3 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o tar -L/usr/local/lib buffer.o checkpoint.o compare.o create.o delete.o exit.o exclist.o extract.o xheader.o incremen.o list.o map.o misc.o names.o sparse.o suffix.o system.o tar.o transform.o unlink.o update.o utf8.o warning.o xattrs.o ../lib/libtar.a ../gnu/libgnu.a -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.3/lib/darwin/libclang_rt.osx.a
复制代码
仔细看 没有 iconv库,虽然 Makefile 中有 LIBICONV = -liconv
但链接时却没有库,原因未知,哎 算了,简朴点直接在 src/Makefile 中修改LDFLAGS 如下:
  1. LDFLAGS = -liconv -v
复制代码
再次 make 乐成!用 gnu tar 打包 ,没有任何问题。那么,用 bsdtar 就没有办法了?还是有的,用man 检察了 bsdtar 的用法 可用下述下令办理:
  1. time bsdtar -c --no-mac-metadata -z -f ~/tmp/Diction4.tgz ./LDOCE5.dictionary ./ccald.dictionary
复制代码
没错,加个 --no-mac-metadata 参数即可,当然这会损失部分mac特有的元数据信息。 
网上有很多对比 bsdtar 和 gnu tar 的,都以为 bsdtar 在 希罕文件有优势,不过履历这个创建文件不报错,解压却会报错的特例,还是警惕为上,最好备份后验证一下;或者选用 gnu tar 吧似乎还没听说过有雷同问题。
一个小小的问题,浪费大半天时间,还是写下来 以备参考。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

伤心客

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表