fontconfig: Branch 'master' - 2 commits

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

 



 src/fcxml.c           |   15 ++--
 test/Makefile.am      |    7 +-
 test/test-migration.c |  172 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 187 insertions(+), 7 deletions(-)

New commits:
commit 6720892e97f11fbe8d69ae5b3875d928c68ff90e
Author: Akira TAGOH <akira@xxxxxxxxx>
Date:   Mon Sep 2 20:52:20 2013 +0900

    Add a test case of the migration for config place

diff --git a/test/Makefile.am b/test/Makefile.am
index 9d5acdd..52c63dc 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -16,14 +16,17 @@ TESTDATA=4x6.pcf 8x16.pcf out.expected fonts.conf.in
 
 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_builddir)
 
+check_PROGRAMS = test-migration
 if HAVE_PTHREAD
-check_PROGRAMS = test-pthread
-noinst_PROGRAMS = $(check_PROGRAMS)
+check_PROGRAMS += test-pthread
 test_pthread_LDADD = $(top_builddir)/src/libfontconfig.la
 # We don't enable this test by default because it will require config and fonts
 # to meaningfully test anything, and we are not installed yet.
 #TESTS += test-pthread
 endif
+noinst_PROGRAMS = $(check_PROGRAMS)
+
+test_migration_LDADD = $(top_builddir)/src/libfontconfig.la
 
 EXTRA_DIST=$(check_SCRIPTS) $(TESTDATA)
 
diff --git a/test/test-migration.c b/test/test-migration.c
new file mode 100644
index 0000000..a0ab839
--- /dev/null
+++ b/test/test-migration.c
@@ -0,0 +1,172 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <fontconfig/fontconfig.h>
+
+FcBool
+mkdir_p(const char *dir)
+{
+    char *parent;
+    FcBool ret;
+
+    if (strlen (dir) == 0)
+	return FcFalse;
+    parent = (char *) FcStrDirname (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;
+
+    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);
+	strcpy (n, dir);
+	n[len] = '/';
+	strcpy (&n[len + 1], e->d_name);
+	if (e->d_type == DT_DIR)
+	{
+	    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)
+{
+    char template[32] = "fontconfig-XXXXXXXX";
+    char *tmp = mkdtemp (template);
+    size_t len = strlen (tmp), xlen, dlen;
+    char xdg[256], confd[256], fn[256], nfn[256], ud[256], nud[256];
+    int ret = -1;
+    FILE *fp;
+    char *content = "<fontconfig></fontconfig>";
+
+    strcpy (xdg, tmp);
+    strcpy (&xdg[len], "/.config");
+    setenv ("HOME", tmp, 1);
+    setenv ("XDG_CONFIG_HOME", xdg, 1);
+    xlen = strlen (xdg);
+    strcpy (confd, xdg);
+    strcpy (&confd[xlen], "/fontconfig");
+    dlen = strlen (confd);
+    /* In case there are no configuration files nor directory */
+    FcInit ();
+    if (access (confd, F_OK) == 0)
+    {
+	fprintf (stderr, "%s unexpectedly exists\n", confd);
+	goto bail;
+    }
+    FcFini ();
+    if (!unlink_dirs (tmp))
+    {
+	fprintf (stderr, "Unable to clean up\n");
+	goto bail;
+    }
+    /* In case there are the user configuration file */
+    strcpy (fn, tmp);
+    strcpy (&fn[len], "/.fonts.conf");
+    strcpy (nfn, confd);
+    strcpy (&nfn[dlen], "/fonts.conf");
+    if (!mkdir_p (confd))
+    {
+	fprintf (stderr, "Unable to create a config dir: %s\n", confd);
+	goto bail;
+    }
+    if ((fp = fopen (fn, "wb")) == NULL)
+    {
+	fprintf (stderr, "Unable to create a config file: %s\n", fn);
+	goto bail;
+    }
+    fwrite (content, sizeof (char), strlen (content), fp);
+    fclose (fp);
+    FcInit ();
+    if (access (nfn, F_OK) != 0)
+    {
+	fprintf (stderr, "migration failed for %s\n", nfn);
+	goto bail;
+    }
+    FcFini ();
+    if (!unlink_dirs (tmp))
+    {
+	fprintf (stderr, "Unable to clean up\n");
+	goto bail;
+    }
+    /* In case there are the user configuration dir */
+    strcpy (ud, tmp);
+    strcpy (&ud[len], "/.fonts.conf.d");
+    strcpy (nud, confd);
+    strcpy (&nud[dlen], "/conf.d");
+    if (!mkdir_p (ud))
+    {
+	fprintf (stderr, "Unable to create a config dir: %s\n", ud);
+	goto bail;
+    }
+    FcInit ();
+    if (access (nud, F_OK) != 0)
+    {
+	fprintf (stderr, "migration failed for %s\n", nud);
+	goto bail;
+    }
+    FcFini ();
+
+    ret = 0;
+bail:
+    unlink_dirs (tmp);
+
+    return ret;
+}
commit 3e5f70a16ac6d54f1e01c92ddaa5985deec1b7f9
Author: Akira TAGOH <akira@xxxxxxxxx>
Date:   Mon Sep 2 20:51:46 2013 +0900

    Do not create a config dir for migration when no config files nor dirs

diff --git a/src/fcxml.c b/src/fcxml.c
index b464b4e..8ff10b6 100644
--- a/src/fcxml.c
+++ b/src/fcxml.c
@@ -2233,11 +2233,6 @@ FcParseInclude (FcConfigParse *parse)
 	    /* No config dir nor file on the XDG directory spec compliant place
 	     * so need to guess what it is supposed to be.
 	     */
-	    FcChar8 *parent = FcStrDirname (s);
-
-	    if (!FcFileIsDir (parent))
-		FcMakeDirectory (parent);
-	    FcStrFree (parent);
 	    if (FcStrStr (s, (const FcChar8 *)"conf.d") != NULL)
 		goto userdir;
 	    else
@@ -2259,6 +2254,11 @@ FcParseInclude (FcConfigParse *parse)
 	{
 	    if (FcFileIsDir (filename))
 	    {
+		FcChar8 *parent = FcStrDirname (userdir);
+
+		if (!FcFileIsDir (parent))
+		    FcMakeDirectory (parent);
+		FcStrFree (parent);
 		if (FcFileIsDir (userdir) ||
 		    rename ((const char *)filename, (const char *)userdir) != 0 ||
 		    symlink ((const char *)userdir, (const char *)filename) != 0)
@@ -2272,6 +2272,11 @@ FcParseInclude (FcConfigParse *parse)
 	    }
 	    else
 	    {
+		FcChar8 *parent = FcStrDirname (userconf);
+
+		if (!FcFileIsDir (parent))
+		    FcMakeDirectory (parent);
+		FcStrFree (parent);
 		if (FcFileIsFile (userconf) ||
 		    rename ((const char *)filename, (const char *)userconf) != 0 ||
 		    symlink ((const char *)userconf, (const char *)filename) != 0)
_______________________________________________
Fontconfig mailing list
Fontconfig@xxxxxxxxxxxxxxxxxxxxx
http://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