append02.at 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Process this file with autom4te to create testsuite. -*- Autotest -*-
  2. # Test suite for GNU tar.
  3. # Copyright 2006-2023 Free Software Foundation, Inc.
  4. # This file is part of GNU tar.
  5. # GNU tar is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3 of the License, or
  8. # (at your option) any later version.
  9. # GNU tar is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. # Using tar 1.15.x the following equivalent command sets:
  16. #
  17. # 1. tar cf archive file1 file2
  18. # and
  19. # 2. tar cfT archive /dev/null
  20. # tar rf archive file1
  21. # tar rt archive file2
  22. #
  23. # produced different archives (GNU format is assumed). It was reported
  24. # by TAMUKI Shoichi on 2006-07-21 [1].
  25. #
  26. # The bug was due to tar being unable to discern between GNU and OLDGNU
  27. # formats and always assuming the latter. The main difference between
  28. # the two is that OLDGNU preserves all bits in the mode field, whereas
  29. # GNU format keeps only the lower 9 ones (mode & 0777).
  30. #
  31. # This was fixed on 2006-07-24 (commit f4e4adea80a) by making tar truncate
  32. # the mode field even in OLDGNU format. Obviously, the fix broke the
  33. # format backward compatibility, but it went unnoticed until 2009-10-03
  34. # (after all, the OLDGNU format is not in much use nowadays), when
  35. # Igor Zhbanov reported it [2].
  36. #
  37. # The final fix was applied on 2009-10-04.
  38. #
  39. # References:
  40. # [1] <[email protected]>
  41. # http://lists.gnu.org/archive/html/bug-tar/2006-07/msg00029.html
  42. # [2] <[email protected]>
  43. # http://lists.gnu.org/archive/html/bug-tar/2009-10/msg00006.html
  44. # The test case below verifies that the equivalent create and append commands
  45. # produce binary equivalent archives for all formats.
  46. AT_SETUP([append vs. create])
  47. AT_KEYWORDS([append append02 append-gnu])
  48. AT_TAR_CHECK([
  49. genfile --file file1
  50. genfile --file file2
  51. # Make sure file timestamps in the archive will not differ
  52. MTIME="--mtime=@0"
  53. # For PAX archives, we need to make sure extended header names are
  54. # reproducible and that their contents won't change with time
  55. if test $[]TEST_TAR_FORMAT = posix; then
  56. TAR_OPTIONS="$TAR_OPTIONS --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=mtime,delete=atime,delete=ctime"
  57. fi
  58. echo Creating archive.1
  59. tar $MTIME -cf archive.1 file1 file2
  60. echo Creating archive.2
  61. tar $MTIME -cf archive.2 -T /dev/null
  62. tar $MTIME -rf archive.2 file1
  63. tar $MTIME -rf archive.2 file2
  64. echo Comparing archives
  65. cmp archive.1 archive.2
  66. ],
  67. [0],
  68. [Creating archive.1
  69. Creating archive.2
  70. Comparing archives
  71. ])
  72. AT_CLEANUP
  73. # End of append02.at