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

 
 

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

Submitted by:  None
Submitted on:  Fri 27 May 2005 07:48:56 PM UTC  
 
Category: findSeverity: 3 - Normal
Item Group: Wrong resultStatus: Invalid
Privacy: PublicAssigned to: James Youngman <jay>
Originator Name: Barry DobynsOriginator Email: -unavailable-
Open/Closed: ClosedRelease: 4.1.20
Fixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project AdministratorIn charge of this item.
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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 4 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Sat 28 May 2005 12:56:39 AM UTCjayStatusNone=>Invalid
  Assigned toNone=>jay
  Open/ClosedOpen=>Closed
Fri 27 May 2005 07:48:56 PM UTCNoneCarbon-Copy-=>Added barry --AT-- dobyns --DOT-- com

Back to the top


Powered by Savane 3.1-cleanup1