fontconfig: Branch 'master' - 2 commits

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

 



 src/fccache.c        |   37 ++++++-
 test/Makefile.am     |    6 +
 test/test-issue107.c |  248 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 285 insertions(+), 6 deletions(-)

New commits:
commit 5f5ec5676c61b9773026a9335c9b0dfa73a73353
Author: Akira TAGOH <akira@xxxxxxxxx>
Date:   Mon Oct 1 07:01:26 2018 +0000

    Do not try updating mtime when unlink was failed

diff --git a/src/fccache.c b/src/fccache.c
index a5e0ea3..87073ba 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -171,20 +171,23 @@ FcDirCacheDeleteUUID (const FcChar8  *dir,
     }
     target = FcStrBuildFilename (d, ".uuid", NULL);
     ret = unlink ((char *) target) == 0;
-    times[0].tv_sec = statb.st_atime;
-    times[1].tv_sec = statb.st_mtime;
+    if (ret)
+    {
+	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;
+	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;
+	times[0].tv_usec = 0;
+	times[1].tv_usec = 0;
 #endif
-    if (utimes ((const char *) d, times) != 0)
-    {
-	fprintf (stderr, "Unable to revert mtime: %s\n", d);
+	if (utimes ((const char *) d, times) != 0)
+	{
+	    fprintf (stderr, "Unable to revert mtime: %s\n", d);
+	}
+	FcHashTableRemove (config->uuid_table, target);
     }
-    FcHashTableRemove (config->uuid_table, target);
     FcStrFree (target);
 bail:
     FcStrFree (d);
commit ff5b49be2be0922f0fb6b9daf08f64a88d2fae6b
Author: Akira TAGOH <akira@xxxxxxxxx>
Date:   Fri Sep 28 09:08:52 2018 +0000

    Do not update mtime when removing .uuid file
    
    This avoids a situation triggers updating caches on a directory where .uuid file was removed.
    
    Resolves: https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/107

diff --git a/src/fccache.c b/src/fccache.c
index 2b60401..a5e0ea3 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -155,17 +155,39 @@ FcDirCacheDeleteUUID (const FcChar8  *dir,
 		      FcConfig       *config)
 {
     const FcChar8 *sysroot = FcConfigGetSysRoot (config);
-    FcChar8 *target;
+    FcChar8 *target, *d;
     FcBool ret = FcTrue;
+    struct stat statb;
+    struct timeval times[2];
 
     if (sysroot)
-	target = FcStrBuildFilename (sysroot, dir, ".uuid", NULL);
+	d = FcStrBuildFilename (sysroot, dir, NULL);
     else
-	target = FcStrBuildFilename (dir, ".uuid", NULL);
-
+	d = FcStrBuildFilename (dir, NULL);
+    if (FcStat (d, &statb) != 0)
+    {
+	ret = FcFalse;
+	goto bail;
+    }
+    target = FcStrBuildFilename (d, ".uuid", NULL);
     ret = unlink ((char *) target) == 0;
+    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 *) d, times) != 0)
+    {
+	fprintf (stderr, "Unable to revert mtime: %s\n", d);
+    }
     FcHashTableRemove (config->uuid_table, target);
-    FcStrFree(target);
+    FcStrFree (target);
+bail:
+    FcStrFree (d);
 
     return ret;
 }
diff --git a/test/Makefile.am b/test/Makefile.am
index 8146353..14b2c13 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -91,6 +91,12 @@ test_bz106632_CFLAGS =					\
 test_bz106632_LDADD = $(top_builddir)/src/libfontconfig.la
 TESTS += test-bz106632
 
+check_PROGRAMS += test-issue107
+test_issue107_LDADD =					\
+	$(top_builddir)/src/libfontconfig.la		\
+	$(NULL)
+TESTS += test-issue107
+
 if !ENABLE_SHARED
 check_PROGRAMS += test-issue110
 test_issue110_CFLAGS =					\
diff --git a/test/test-issue107.c b/test/test-issue107.c
new file mode 100644
index 0000000..7f4bfb0
--- /dev/null
+++ b/test/test-issue107.c
@@ -0,0 +1,248 @@
+/*
+ * fontconfig/test/test-issue107.c
+ *
+ * Copyright © 2000 Keith Packard
+ * Copyright © 2018 Akira TAGOH
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the author(s) not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  The authors make no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <errno.h>
+#ifndef HAVE_STRUCT_DIRENT_D_TYPE
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif
+#include <fontconfig/fontconfig.h>
+
+#ifdef _WIN32
+#  define FC_DIR_SEPARATOR         '\\'
+#  define FC_DIR_SEPARATOR_S       "\\"
+#else
+#  define FC_DIR_SEPARATOR         '/'
+#  define FC_DIR_SEPARATOR_S       "/"
+#endif
+
+extern FcChar8 *FcConfigRealFilename (FcConfig *, FcChar8 *);
+
+#ifdef HAVE_MKDTEMP
+#define fc_mkdtemp	mkdtemp
+#else
+char *
+fc_mkdtemp (char *template)
+{
+    if (!mktemp (template) || mkdir (template, 0700))
+	return NULL;
+
+    return template;
+}
+#endif
+
+FcBool
+mkdir_p (const char *dir)
+{
+    char *parent;
+    FcBool ret;
+
+    if (strlen (dir) == 0)
+	return FcFalse;
+    parent = (char *) FcStrDirname ((const FcChar8 *) dir);
+    if (!parent)
+	return FcFalse;
+    if (access (parent, F_OK) == 0)
+	ret = mkdir (dir, 0755) == 0 && chmod (dir, 0755) == 0;
+    else if (access (parent, F_OK) == -1)
+	ret = mkdir_p (parent) && (mkdir (dir, 0755) == 0) && chmod (dir, 0755) == 0;
+    else
+	ret = FcFalse;
+    free (parent);
+
+    return ret;
+}
+
+FcBool
+unlink_dirs (const char *dir)
+{
+    DIR *d = opendir (dir);
+    struct dirent *e;
+    size_t len = strlen (dir);
+    char *n = NULL;
+    FcBool ret = FcTrue;
+#ifndef HAVE_STRUCT_DIRENT_D_TYPE
+    struct stat statb;
+#endif
+
+    if (!d)
+	return FcFalse;
+    while ((e = readdir (d)) != NULL)
+    {
+	size_t l;
+
+	if (strcmp (e->d_name, ".") == 0 ||
+	    strcmp (e->d_name, "..") == 0)
+	    continue;
+	l = strlen (e->d_name) + 1;
+	if (n)
+	    free (n);
+	n = malloc (l + len + 1);
+	if (!n)
+	{
+	    ret = FcFalse;
+	    break;
+	}
+	strcpy (n, dir);
+	n[len] = FC_DIR_SEPARATOR;
+	strcpy (&n[len + 1], e->d_name);
+#ifdef HAVE_STRUCT_DIRENT_D_TYPE
+	if (e->d_type == DT_DIR)
+#else
+	if (stat (n, &statb) == -1)
+	{
+	    fprintf (stderr, "E: %s\n", n);
+	    ret = FcFalse;
+	    break;
+	}
+	if (S_ISDIR (statb.st_mode))
+#endif
+	{
+	    if (!unlink_dirs (n))
+	    {
+		fprintf (stderr, "E: %s\n", n);
+		ret = FcFalse;
+		break;
+	    }
+	}
+	else
+	{
+	    if (unlink (n) == -1)
+	    {
+		fprintf (stderr, "E: %s\n", n);
+		ret = FcFalse;
+		break;
+	    }
+	}
+    }
+    if (n)
+	free (n);
+    closedir (d);
+
+    if (rmdir (dir) == -1)
+    {
+	fprintf (stderr, "E: %s\n", dir);
+	return FcFalse;
+    }
+
+    return ret;
+}
+
+int
+main(void)
+{
+    FcConfig *cfg = FcConfigCreate ();
+    char *basedir, template[512] = "/tmp/fc107-XXXXXX";
+    char *sysroot, systempl[512] = "/tmp/fc107-XXXXXX";
+    FcChar8 *d = NULL, *dd = NULL;
+    FcCache *c = NULL;
+    const FcChar8 *doc = ""
+	"<fontconfig>\n"
+	"  <dir>%s</dir>\n"
+	"</fontconfig>\n"
+	"";
+    int retval = 0;
+    size_t len;
+
+    retval++;
+    basedir = fc_mkdtemp (template);
+    if (!basedir)
+    {
+	fprintf (stderr, "%s: %s\n", template, strerror (errno));
+	goto bail;
+    }
+    retval++;
+    sysroot = fc_mkdtemp (systempl);
+    if (!sysroot)
+    {
+	fprintf (stderr, "%s: %s\n", systempl, strerror (errno));
+	goto bail;
+    }
+    retval++;
+    fprintf (stderr, "D: Creating %s\n", basedir);
+    mkdir_p (basedir);
+    len = strlen (doc) + strlen (basedir) + 1;
+    dd = malloc (len);
+    snprintf (dd, len, doc, basedir);
+    if (!FcConfigParseAndLoadFromMemory (cfg, dd, FcFalse))
+    {
+	fprintf (stderr, "%s: Unable to load a config\n", basedir);
+	goto bail;
+    }
+    sleep (1);
+    c = FcDirCacheRead (basedir, FcFalse, cfg);
+    FcDirCacheUnload (c);
+    sleep (1);
+    retval++;
+    if (!FcConfigUptoDate (cfg))
+    {
+	fprintf (stderr, "updated. need to reload.\n");
+	goto bail;
+    }
+    setenv ("FONTCONFIG_SYSROOT", sysroot, 1);
+    fprintf (stderr, "D: Creating %s\n", sysroot);
+    mkdir_p (sysroot);
+    retval++;
+    d = FcStrBuildFilename (sysroot, basedir, NULL);
+    fprintf (stderr, "D: Creating %s\n", d);
+    mkdir_p (d);
+    free (d);
+    retval++;
+    free (dd);
+    len = strlen (doc) + strlen (basedir) + 1;
+    dd = malloc (len);
+    snprintf (dd, len, doc, basedir);
+    if (!FcConfigParseAndLoadFromMemory (cfg, dd, FcFalse))
+    {
+	fprintf (stderr, "%s: Unable to load a config\n", basedir);
+	goto bail;
+    }
+    sleep (1);
+    c = FcDirCacheRead (basedir, FcFalse, cfg);
+    FcDirCacheUnload (c);
+    sleep (1);
+    retval++;
+    if (!FcConfigUptoDate (cfg))
+    {
+	fprintf (stderr, "updated. need to reload (sysroot)\n");
+	goto bail;
+    }
+    retval = 0;
+bail:
+    fprintf (stderr, "Cleaning up\n");
+    unlink_dirs (basedir);
+    if (dd)
+	free (dd);
+    FcConfigDestroy (cfg);
+
+    return retval;
+}
_______________________________________________
Fontconfig mailing list
Fontconfig@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/fontconfig




[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux