Do not update mtime with creating .uuid

This commit is contained in:
Akira TAGOH 2017-12-18 21:26:29 +09:00
parent c1e48b0c14
commit 182186e53a
2 changed files with 39 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include <limits.h> #include <limits.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h>
#include <assert.h> #include <assert.h>
#if defined(HAVE_MMAP) || defined(__CYGWIN__) #if defined(HAVE_MMAP) || defined(__CYGWIN__)
# include <unistd.h> # include <unistd.h>
@ -63,7 +64,14 @@ FcDirCacheCreateUUID (FcChar8 *dir,
uuid_t uuid; uuid_t uuid;
char out[37]; char out[37];
FcBool (* hash_add) (FcHashTable *, void*, void*); FcBool (* hash_add) (FcHashTable *, void*, void*);
struct stat statb;
struct timeval times[2];
if (FcStat (dir, &statb) != 0)
{
ret = FcFalse;
goto bail1;
}
atomic = FcAtomicCreate (uuidname); atomic = FcAtomicCreate (uuidname);
if (!atomic) if (!atomic)
{ {
@ -101,6 +109,24 @@ FcDirCacheCreateUUID (FcChar8 *dir,
FcAtomicUnlock (atomic); FcAtomicUnlock (atomic);
bail2: bail2:
FcAtomicDestroy (atomic); FcAtomicDestroy (atomic);
if (ret)
{
/* revert mtime of the directory */
times[0].tv_sec = statb.st_atime;
times[1].tv_sec = statb.st_mtime;
#ifdef HAVE_STRUCT_STAT_ST_MTIM
times[0].tv_usec = statb.st_atim.tv_nsec / 1000;
times[1].tv_usec = statb.st_mtim.tv_nsec / 1000;
#else
times[0].tv_usec = 0;
times[1].tv_usec = 0;
#endif
if (utimes ((const char *) dir, times) != 0)
{
fprintf (stderr, "Unable to revert mtime: %s\n", dir);
}
}
} }
bail1: bail1:
FcStrFree (uuidname); FcStrFree (uuidname);

View File

@ -164,6 +164,19 @@ if [ $n != 1 ]; then
exit 1 exit 1
fi fi
dotest "Keep mtime of the font directory"
prep
cp $FONT1 $FONTDIR
touch -d @0 $FONTDIR
stat $FONTDIR | grep Modify > out1
$FCCACHE $FONTDIR
stat $FONTDIR | grep Modify > out2
if cmp out1 out2 > /dev/null ; then : ; else
echo "*** Test failed: $TEST"
echo "mtime was modified"
exit 1
fi
if [ x"$BWRAP" != "x" ]; then if [ x"$BWRAP" != "x" ]; then
dotest "Basic functionality with the bind-mounted cache dir" dotest "Basic functionality with the bind-mounted cache dir"
prep prep