summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fccache.c26
-rw-r--r--test/run-test.sh13
2 files changed, 39 insertions, 0 deletions
diff --git a/src/fccache.c b/src/fccache.c
index dfe9520f..33c8a11f 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -30,6 +30,7 @@
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <assert.h>
#if defined(HAVE_MMAP) || defined(__CYGWIN__)
# include <unistd.h>
@@ -63,7 +64,14 @@ FcDirCacheCreateUUID (FcChar8 *dir,
uuid_t uuid;
char out[37];
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);
if (!atomic)
{
@@ -101,6 +109,24 @@ FcDirCacheCreateUUID (FcChar8 *dir,
FcAtomicUnlock (atomic);
bail2:
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:
FcStrFree (uuidname);
diff --git a/test/run-test.sh b/test/run-test.sh
index 4154dd3e..436dee17 100644
--- a/test/run-test.sh
+++ b/test/run-test.sh
@@ -164,6 +164,19 @@ if [ $n != 1 ]; then
exit 1
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
dotest "Basic functionality with the bind-mounted cache dir"
prep