tjko / jpegoptim

jpegoptim - utility to optimize/compress JPEG files
http://www.iki.fi/tjko/projects.html
GNU General Public License v3.0
1.56k stars 116 forks source link

Preserve nanosecond timestamps if available. #82

Closed GerbilSoft closed 2 years ago

GerbilSoft commented 3 years ago

jpegoptim's -p option currently only preserves timestamps at a 1-second resolution. This PR makes use of stat.st_mtim and futimens() to preserve nanosecond-resolution timestamps.

tjko commented 3 years ago

Thanks for the patch.

Seems like it would be cleaner to use utimensat() instead of futimens(), though?
As it would save the overhead having to open file...

Should be able to simply do something like the following?

if (utimensat(AT_FDCWD, outfile, time_save, 0) != 0)
    warn("failed to reset output file time/date");
GerbilSoft commented 3 years ago

Yeah, that should work. I didn't see that particular part of the documentation for utimensat(), so I didn't realize dirfd wasn't required.

Will update this and push the changes.

tjko commented 3 years ago

Thanks, I merged the change to use utimensat().

Can you explain what the configure change is doing exactly?

I didn't notice any problem doing "out-of-tree" build without this change...

mkdir /tmp/build
cd /tmp/build
${HOME}/src/jpegoptim/configure
make
GerbilSoft commented 3 years ago

When I tried an out-of-tree build, I ended up getting this error:

$ ../configure
$ make
gcc  -g -O2  -DHAVE_CONFIG_H   -c -o jpegoptim.o ../jpegoptim.c
../jpegoptim.c:13:10: fatal error: config.h: No such file or directory
   13 | #include "config.h"
      |          ^~~~~~~~~~
compilation terminated.
make: *** [<builtin>: jpegoptim.o] Error 1

config.h is located in the build directory, and gcc doesn't add the current directory to the include path on my system.

Also, I forgot to remove the HAVE_FILENO check, which isn't needed with utimensat().

tjko commented 3 years ago

Odd, I can't seem to replicate that behavior. Does the generated Makefile contain correct VPATH setting? (and you're using GNU Make?)

$ mkdir build
$ cd build
$ ../configure
$ make
gcc  -g -O2  -DHAVE_CONFIG_H   -c -o jpegoptim.o ../jpegoptim.c
gcc  -g -O2  -DHAVE_CONFIG_H   -c -o jpegdest.o ../jpegdest.c
gcc  -g -O2  -DHAVE_CONFIG_H   -c -o misc.o ../misc.c
gcc  -g -O2  -DHAVE_CONFIG_H -o jpegoptim jpegoptim.o jpegdest.o misc.o   -lm -ljpeg