bug-coreutils
[Top][All Lists]
Advanced

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

Re: touch --inside: new option for gzipped files


From: Paul Eggert
Subject: Re: touch --inside: new option for gzipped files
Date: 27 May 2003 12:30:37 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

I like this idea and have the following further suggestion for it:

> + @item -i
> + @itemx --inside
> + @opindex -i
> + @opindex --inside
> + Use the time found inside the file instead of the current time.  This
> + works for files in GZIP format; support for other file formats may be
> + added at a later date.  If the file is not of one of the supported formats
> + or doesn't have a timestamp inside it, it is not touched.

Here I would also mention that the time is that of the first member of
in the GZIP archive.  This normally doesn't matter for GNU gzip, but
it can be an issue when you concatenate several gzipped files (which
is allowed).

> +     unsigned long time =
> +       ((((((unsigned long) buf[7] << 8)
> +           | (unsigned long) buf[6]) << 8)
> +         | (unsigned long) buf[5]) << 8)
> +       | (unsigned long) buf[4];
> + 
> +     if (time)

This does not check for negative times (RFC1952 does not allow
negative times).  Also, POSIX allows an implementation where time_t
would overflow; I don't know of any platform where this would happen,
but might as well be safe if it's easy.  One fix is to do something
like this instead:

        unsigned long int header_mtime =
          (((unsigned long int) buf[7] << 24)
           | ((unsigned long int) buf[6] << 16)
           | ((unsigned long int) buf[5] << 8)
           | (unsigned long int) buf[4]);
        time_t time = header_mtime;

        if (time == header_mtime && 0 < time)

Hmm, come to think of it, gzip itself probably mishandles negative
times; I'll look into that.




reply via email to

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