image: Use sub-second time info when available

This commit is contained in:
Kim Woelders 2023-07-06 19:49:56 +02:00
parent cf5b462d92
commit a1ea31e070
5 changed files with 35 additions and 14 deletions

View File

@ -269,6 +269,9 @@ EC_C_VISIBILITY(yes)
EC_C_PACKING()
EC_C_ASAN()
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec])
AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec])
VERSION_MAJOR=`echo $VERSION | awk -F. '{print $1}'`
VERSION_MINOR=`echo $VERSION | awk -F. '{print $2}'`
VERSION_MICRO=`echo $VERSION | awk -F. '{print $3}'`

View File

@ -124,7 +124,28 @@ __imlib_FileIsFile(const char *s)
return (S_ISREG(st.st_mode)) ? 1 : 0;
}
time_t
#define STONS 1000000000ULL
uint64_t
__imlib_StatModDate(const struct stat *st)
{
uint64_t mtime_ns, ctime_ns;
#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
mtime_ns = st->st_mtim.tv_sec * STONS + st->st_mtim.tv_nsec;
ctime_ns = st->st_ctim.tv_sec * STONS + st->st_ctim.tv_nsec;
#elif HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
mtime_ns = st->st_mtimespec.tv_sec * STONS + st->st_mtimespec.tv_nsec;
ctime_ns = st->st_ctimespec.tv_sec * STONS + st->st_ctimespec.tv_nsec;
#else
mtime_ns = st->st_mtime;
ctime_ns = st->st_ctime;
#endif
return (mtime_ns > ctime_ns) ? mtime_ns : ctime_ns;
}
uint64_t
__imlib_FileModDate(const char *s)
{
struct stat st;
@ -134,10 +155,10 @@ __imlib_FileModDate(const char *s)
if (__imlib_FileStat(s, &st))
return 0;
return (st.st_mtime > st.st_ctime) ? st.st_mtime : st.st_ctime;
return __imlib_StatModDate(&st);
}
time_t
uint64_t
__imlib_FileModDateFd(int fd)
{
struct stat st;
@ -145,7 +166,7 @@ __imlib_FileModDateFd(int fd)
if (fstat(fd, &st) < 0)
return 0;
return (st.st_mtime > st.st_ctime) ? st.st_mtime : st.st_ctime;
return __imlib_StatModDate(&st);
}
char **

View File

@ -1,7 +1,7 @@
#ifndef __FILE_H
#define __FILE_H 1
#include <time.h>
#include <stdint.h>
#include <sys/stat.h>
char *__imlib_FileKey(const char *file);
@ -9,11 +9,7 @@ char *__imlib_FileRealFile(const char *file);
const char *__imlib_FileExtension(const char *file);
static inline time_t
__imlib_StatModDate(const struct stat *st)
{
return (st->st_mtime > st->st_ctime) ? st->st_mtime : st->st_ctime;
}
uint64_t __imlib_StatModDate(const struct stat *st);
static inline int
__imlib_StatIsFile(const struct stat *st)
@ -28,8 +24,9 @@ __imlib_StatIsDir(const struct stat *st)
}
int __imlib_FileIsFile(const char *s);
time_t __imlib_FileModDate(const char *s);
time_t __imlib_FileModDateFd(int fd);
uint64_t __imlib_FileModDate(const char *s);
uint64_t __imlib_FileModDateFd(int fd);
char **__imlib_FileDir(const char *dir, int *num);
void __imlib_FileFreeDirList(char **l, int num);

View File

@ -498,7 +498,7 @@ __imlib_LoadImage(const char *file, ImlibLoadArgs * ila)
{
if (IM_FLAG_ISSET(im, F_ALWAYS_CHECK_DISK))
{
time_t current_modified_time;
uint64_t current_modified_time;
current_modified_time = ila->fp ?
__imlib_FileModDateFd(fileno(ila->fp)) :

View File

@ -70,7 +70,7 @@ struct _ImlibImage {
char *file;
char *key;
time_t moddate;
uint64_t moddate;
unsigned int flags;
int references;
char *format;