Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!europa.asd.contel.com!gatech!rutgers!modus!otello!gear!am!alex From: alex@am.sublink.org (Alex Martelli) Newsgroups: comp.unix.shell Subject: Re: Retaining file modification times Message-ID: <1991May23.211830.362@am.sublink.org> Date: 23 May 91 21:18:30 GMT References: <9105211828.AA12327@fozzie.nrl.navy.mil> Organization: Premiata Famiglia Martelli & Figli Lines: 81 phillips@FOZZIE.NRL.NAVY.MIL (Lee Phillips) writes: :I want to do something to a file without changing its modification :time. I suppose I can write a script to get the time from ls, do the :modification, then restore the time (after converting it to numerical :format) with /usr/5bin/touch, but I'm hoping that there is an easier :way. (Csh solutions preferred.) Would you settle for a C solution without the 'sh'?-) I think it's easier than transforming ls's output into a form acceptable for touch. ---cut here: ti.c #include #include #include extern char*malloc(); int main(argc, argv) int argc; char **argv; { struct utimbuf {time_t actime, modtime;} *timar=0; struct stat bufi; int i,pid,waitrc; unsigned int sonrc; if(argc<2) { fprintf(stderr,"Usage: %s command [files]\n",argv[0]); return 1; } if(argc>2) { timar=(struct utimbuf*)malloc((argc-2)); for(i=2; i>8; } ---end cut: ti.c This is rather a kludge, actually. The syntax (after 'cc -o ti ti.c') is 'ti command -maybe -some -options file arguments...', but I don't want ti to have to "know" about the syntax of "command" to discern which of the following words are filenames, and which are not. So what ti does is try to stat() *each* of its args; then, after fork/exec/wait of command, it tries to restore actime and modtime for each arg that it was originally able to stat successfully - I figured this would be mostly harmless, i.e. even if you DO have a file called '-l', doing, say, 'ti ci -l a.c b.c c.c', the fact that '-l' is NOT being modified by the (RCS check-in-then-check-out-again,locked) target command will not normally be a problem (the times of file '-l' will be harmlessly restored to what they already were...). You may want to adopt some alternative approach, such as parsing the target command's arguments according to some option-syntax convention. Other problems have to do with such commands as 'ti sort -ofo fi', where file 'fo' is going to be modified but is not easily recognizable as a part of the target command; also 'ti sort fi >fo', since the shell is not going to let ti know that its output is redirected to fo... Anyway, the main way I use it is just as in the first example above - I definitely do NOT want source files' modtimes to be updated when they are just, conceptually, being checked-in, not 'modified'... such updates were impeding my intended usage of make+rcs before I came up with this kludgey but basically workable solution. -- Alex Martelli - (home snailmail:) v. Barontini 27, 40138 Bologna, ITALIA Email: (work:) martelli@cadlab.sublink.org, (home:) alex@am.sublink.org Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434; Fax: ++39 (51) 366964 (work only), Fidonet: 332/401.3 (home only).