Bug 495686 - tar --keep-newer-files removes the old files
tar --keep-newer-files removes the old files
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: tar (Show other bugs)
5.3
All Linux
high Severity high
: rc
: ---
Assigned To: Ondrej Vasik
BaseOS QE
:
Depends On:
Blocks: 499522
  Show dependency treegraph
 
Reported: 2009-04-14 08:24 EDT by Olivier Fourdan
Modified: 2013-03-03 21:48 EST (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-03-30 04:19:01 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Proposed patch (847 bytes, patch)
2009-04-14 08:24 EDT, Olivier Fourdan
no flags Details | Diff

  None (edit)
Description Olivier Fourdan 2009-04-14 08:24:40 EDT
Created attachment 339473 [details]
Proposed patch

Description of problem:

tar --keep-newer-files will keep newer files but remove the old ones.

Version-Release number of selected component (if applicable):

tar-1.15.1-23.0.1

How reproducible:

100% reproducible

Steps to Reproduce:
1. Prepare a test directory

  $ mkdir test; 
  $ for i in a b c; do echo $(date) > test/$i; done; 

2. Create an archive on that directory

  $ tar cvf test.tar test;

3. Modify the file to have one older file and one newer (leaving one untouched)

  $ echo 0801010101 > test/a; touch -t 0801010101 test/a
  $ echo 1001010101 > test/c; touch -t 1001010101 test/c
  $ ls -l test
  total 12
  -rw-rw-r-- 1 ofourdan ofourdan 11 Jan  1  2008 a
  -rw-rw-r-- 1 ofourdan ofourdan 29 Apr 14 13:00 b
  -rw-rw-r-- 1 ofourdan ofourdan 11 Jan  1  2010 c

4. Restore the archive with "--keep-newer-files"
  
Actual results:

The file "test/a" is removed:

  $ tar --keep-newer-files -xf test.tar
  tar: Current `test/b' is newer
  tar: test/a: Warning: Cannot stat: No such file or directory
  tar: Current `test/a' is newer
  tar: Current `test/c' is newer

  $ ls -l test
  total 8
  -rw-rw-r-- 1 ofourdan ofourdan 29 Apr 14 13:06 b
  -rw-rw-r-- 1 ofourdan ofourdan 11 Jan  1  2010 c


Expected results:

No file is removed by tar:

  $ tar --keep-newer-files -xf test.tar
  tar: Current `test/b' is newer
  tar: Current `test/c' is newer

  $ ls -l test
  total 12
  -rw-rw-r-- 1 ofourdan ofourdan 29 Apr 14 13:06 a
  -rw-rw-r-- 1 ofourdan ofourdan 29 Apr 14 13:06 b
  -rw-rw-r-- 1 ofourdan ofourdan 11 Jan  1  2010 c

Additional info:

The code in src/extract.c in charge of that has been heavily modified between tar 1.15.1 and tar 1.16. 

However, we do not need to backport all of the changes (or even rebase tar to 1.16 or newer), a backport based on git commit should suffice:

http://git.savannah.gnu.org/cgit/tar.git/commit/?id=8d064bb816bf37dbe3e8455322281639a33e2851

However with that has two drawbacks:

1) It breaks i18n by changing the message
2) The warning with stat() remains

Attaching a similar patch that does not change the message (to keep gettext happy) and that also avoid the warning from stat().
Comment 2 Ondrej Vasik 2009-04-14 08:53:15 EDT
Thanks for report and patch. I guess as #2 is the behaviour in upstream and fedora rawhide, it would mean small differencing between RHEL-5 and future RHEL-6. Anyway it's just cosmetic difference, so I'll probably use your patch to avoid #1.
Comment 3 Olivier Fourdan 2009-04-15 03:56:27 EDT
(In reply to comment #2)
> Thanks for report and patch. I guess as #2 is the behaviour in upstream and
> fedora rawhide, it would mean small differencing between RHEL-5 and future
> RHEL-6. Anyway it's just cosmetic difference, so I'll probably use your patch
> to avoid #1.  

No, #2 (the stat() error message) does not show in recent tar because the extract procedure has been heavily modified between tar 1.15.1 and 1.16 so the unlink() and stat() are not done in the same order apparently (based on traces added in tar 1.16).

So the proposed patch actually produces the same output as the tar 1.16 (beside the slight difference in the message):

  $ ./tar-1.16/src/tar --keep-newer-files -xf test.tar
  ./tar-1.16/src/tar: Current `test/b' is newer or same age
  ./tar-1.16/src/tar: Current `test/c' is newer or same age
  $ ls -l test
  total 12
  -rw-rw-r-- 1 ofourdan ofourdan 29 Apr 14 13:06 a
  -rw-rw-r-- 1 ofourdan ofourdan 29 Apr 14 13:06 b
  -rw-rw-r-- 1 ofourdan ofourdan 11 Jan  1  2010 c
Comment 15 errata-xmlrpc 2010-03-30 04:19:01 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2010-0224.html

Note You need to log in before you can comment on or make changes to this bug.