bugfindutils - Bugs: bug #13212, -newer only examines it's target...

 
 

bug #13212: -newer only examines it's target once at the start

Submitter:  None
Submitted:  Fri 27 May 2005 07:48:56 PM UTC
   
 
Category:  find Severity:  3 - Normal
Item Group:  Wrong result Status:  Invalid
Privacy:  Public Assigned to:  jay
Originator Name:  Barry Dobyns Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  4.1.20
Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 28 May 2005 12:56:39 AM UTC, comment #1: 

I'm not sure you really are using GNU find.  GNU find doesn't have an "-f" option.

Anyway, I'm not going to make the change you suggest, for several reasons:

1. It's not unlikely that there are also scripts which assume the reverse behaviour, because for example they are trying to generate  some kind of incremental backup and need the timestamp to be unchanged.   This applies especially to -anewer. 

2.  There are lots of other ways to achieve the sort of thing you have in mind.  Here are two (untested) examples:

# an obvious way
find "$START" -newer "$TARGET" -exec test {} -nt "$TARGET" ";" -exec touch -r "{}" "$TARGET" ";"

# an efficient way (for larger directory trees)
touch -r "$(find $START -printf "%T@:%p\n" | (unset LANG LC_COLLATE; sort -n ) | sed -ne '$ p' | cut -d: -f2-)" "$TARGET"

Lastly, findutils 4.1.7 is quite old now.  If you are planning to report bugs in findutils, please check that current versions are not affected (in this case findutils version 4.2.20).

James Youngman <jay>
Group administrator
Fri 27 May 2005 07:48:56 PM UTC, original submission:  

Actually Release 4.1.7, debian woody.  Debian is always so up-to-date.

-newer only examines the target once

Consider the case where I'm trying to write a script that sets some "target" file to the latest time of a large number of other files that I'm using find to traverse. 

I write

find $START -f -newer $TARGET -exec touch -r "{}" $TARGET ";"

but this only gets the time set to the last file that find examines  that was -newer than the $TARGET's mod time before the command began to execute.

My work-around for the line above is to execute until it produces no output, but that's unpleasant, especially if the structure traversed by find is large.

while true
do
   findout=`find $START -f -newer $TARGET \
            -exec touch -r "{}" $TARGET ";" -print | tail -1`
   if [ -z $findout ] ; then break ; fi
done

After some reflection, I believe that the general case of this sort of problem occur when I'm using -exec.

So, I can understand a line of argument that goes that mine is an exceptional case, and the current behavior of -newer works well for everyone else in the world.  Indeed, in the general case where the action of the -exec command does not modify one of the predicates, only taking the time once is a reasonable and much-to-be-desired optimization.

Anywho, please consider changing the behavior of -newer such that it performs the current behavior (check the time once) if and only if there are no -exec arguments elsewhere in the predicate, and check the time every time if there are -exec arguments elsewhere. 

Or, (ugh!) add either another time test predicate that checks every time (for use with find | xargs constructions).

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

Only logged-in users can vote.

 

Follow 4 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2005-05-28 jay StatusNone Invalid
    Assigned toNone jay
    Open/ClosedOpen Closed
2005-05-27 None Carbon-Copy- Added barry --AT-- dobyns --DOT-- com

Back to the top

Powered by Savane 3.12.
Corresponding source code