chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH] Make setting of the file modification time san


From: Peter Bex
Subject: [Chicken-hackers] [PATCH] Make setting of the file modification time saner
Date: Wed, 10 May 2017 22:51:52 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

Hi all,

While working on the docs for (chicken file posix), I noticed some
discrepancies:

- file-access-time and file-change-time have no associated setter,
   but file-modification-time does.
- The setter for file-modification-time sets both mtime AND atime,
   even though (set! (file-modification-time f) x) implies that
   we're setting ONLY the mtime.
- The getters all accept strings, ports and file descriptors; the
   setter only accepts a string.

The first patch improves the situation by getting rid of the generalised
setter, and opting for a simpler approach.  There's no (easy) way to
influence the file-change-time, so adding setters to all of them and
making the setter for file-modification-time only change the modification
time is a no-go, so I decided to just add a set-file-times! procedure.

The name of this procedure is taken from MIT Scheme / SCSH.  SCSH
doesn't add a bang at the end, but we do for our other set-* procedures
in posix.scm, so I decided to go with the MIT convention.
Other Schemes have kind of inconsistent names like "touch-file"
(Gauche), utime (Guile), or some ridiculously long ones like
"file-last-access-and-modification-times-set!" (Gambit) and
"file-or-directory-modify-seconds" (Racket).  Chez doesn't appear
to have anything to change the timestamps (though I really like their
nice consistent naming for the accessors and whether to follow links;
perhaps we can adopt that too?).

For maximum compatibility with both MIT and SCSH, #f means to keep
the original timestamp, but omitting both means to set the timestamp
to the current time.  If only one argument is supplied, the second is
assumed to be the same (this keeps it as conveniently like the old
setter).  To make it keep the original timestamp, I added an
lstat() call to set_file_mtime; utime() also follows symlinks.

So, to clarify:

- (set-file-times! "file") is a simple "touch" of the file: both times
    are set to the current timestamp.

- (set-file-times! "file" 0) will set both atime and mtime to the epoch,
    just like (set! (file-modification-time "file") 0) in the original
    situation would do.

- (set-file-times! "file" #f 0) will keep the atime unchanged, but set
   the mtime to the epoch.

- (set-file-times! "file" 0 #f) will set the atime to the epoch and keep
   the mtime unchanged.

- (set-file-times! "file" #f) will not change either timestamp.

- All of the above _will_ (necessarily) touch the ctime.

Finally, the second patch is a simple improvement of the types database
to reflect the fact that the file-*-time accessors all also accept a
port, in addition to a string or fixnum.

We could consider extending set-file-times! to accept these too, but
that's a bit trickier, as there's AFAIK no portable way to change the
times on an FD.

Cheers,
Peter

Attachment: 0001-Replace-file-modification-time-setter-with-set-file-.patch
Description: Text Data

Attachment: 0002-Add-port-to-accepted-file-timestamp-argument-types.patch
Description: Text Data

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]