fontconfig: Branch 'master' - 2 commits

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

 



 .gitlab-ci.yml       |   23 +++-
 src/fccfg.c          |   20 +--
 test/Makefile.am     |   30 +++++
 test/test-d1f48f11.c |  283 +++++++++++++++++++++++++++++++++++++++++++++++++++
 test/test-issue110.c |  245 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 590 insertions(+), 11 deletions(-)

New commits:
commit ba206df9b9a7ca300265f650842c1459ff7c634a
Author: Akira TAGOH <akira@xxxxxxxxx>
Date:   Wed Sep 5 12:08:52 2018 +0000

    Add a test case for d1f48f11

diff --git a/test/Makefile.am b/test/Makefile.am
index 9f4d48a..8146353 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -105,6 +105,20 @@ test_issue110_LDADD =					\
 	$(top_builddir)/src/libfontconfig.la		\
 	$(NULL)
 TESTS += test-issue110
+
+check_PROGRAMS += test-d1f48f11
+test_d1f48f11_CFLAGS =					\
+	-I$(top_builddir)				\
+	-I$(top_builddir)/src				\
+	-I$(top_srcdir)					\
+	-I$(top_srcdir)/src				\
+	-DHAVE_CONFIG_H					\
+	-DFONTCONFIG_PATH='"$(BASECONFIGDIR)"'		\
+	$(NULL)
+test_d1f48f11_LDADD =					\
+	$(top_builddir)/src/libfontconfig.la		\
+	$(NULL)
+TESTS += test-d1f48f11
 endif
 
 EXTRA_DIST=run-test.sh run-test-conf.sh $(TESTDATA) out.expected-long-family-names out.expected-no-long-family-names
diff --git a/test/test-d1f48f11.c b/test/test-d1f48f11.c
new file mode 100644
index 0000000..6c0ecf0
--- /dev/null
+++ b/test/test-d1f48f11.c
@@ -0,0 +1,283 @@
+/*
+ * fontconfig/test/test-d1f48f11.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 *);
+extern FcChar8 *FcStrCanonFilename (const 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;
+}
+
+char template[512] = "/tmp/fc-d1f48f11-XXXXXX";
+char systempl[512] = "/tmp/fc-d1f48f11-XXXXXX";
+char *rootdir, *sysroot;
+
+int
+setup (char *dir)
+{
+    FcChar8 *confdir = NULL, *availdir = NULL, *real = NULL, *link = NULL;
+    FILE *fp;
+    int ret = 1;
+
+    confdir = FcStrBuildFilename (dir, "conf.d", NULL);
+    availdir = FcStrBuildFilename (dir, "conf.avail", NULL);
+    mkdir_p (confdir);
+    mkdir_p (availdir);
+    real = FcStrBuildFilename (availdir, "00-foo.conf", NULL);
+    link = FcStrBuildFilename (confdir, "00-foo.conf", NULL);
+    if (!real || !link)
+    {
+	fprintf (stderr, "E: unable to allocate memory\n");
+	goto bail;
+    }
+    if ((fp = fopen (real, "wb")) == NULL)
+    {
+	fprintf (stderr, "E: unable to open a file\n");
+	goto bail;
+    }
+    fprintf (fp, "%s", real);
+    fclose (fp);
+    if (symlink ("../conf.avail/00-foo.conf", link) != 0)
+    {
+	fprintf (stderr, "%s: %s\n", link, strerror (errno));
+	goto bail;
+    }
+    ret = 0;
+bail:
+    if (real)
+	free (real);
+    if (link)
+	free (link);
+    if (availdir)
+	free (availdir);
+    if (confdir)
+	free (confdir);
+
+    return ret;
+}
+
+void
+teardown (const char *dir)
+{
+    unlink_dirs (dir);
+}
+
+int
+main (void)
+{
+    FcConfig *cfg = NULL;
+    FcChar8 *dc = NULL, *da = NULL, *d = NULL;
+    FcChar8 *ds = NULL, *dsa = NULL, *dsac = NULL;
+    int ret = 1;
+
+    rootdir = fc_mkdtemp (template);
+    if (!rootdir)
+    {
+	fprintf (stderr, "%s: %s\n", template, strerror (errno));
+	return 1;
+    }
+    sysroot = fc_mkdtemp (systempl);
+    if (!sysroot)
+    {
+	fprintf (stderr, "%s: %s\n", systempl, strerror (errno));
+	return 1;
+    }
+    ds = FcStrBuildFilename (sysroot, rootdir, NULL);
+    
+    if (setup (rootdir) != 0)
+	goto bail;
+    if (setup (ds) != 0)
+	goto bail;
+
+    dc = FcStrBuildFilename (rootdir, "conf.d", "00-foo.conf", NULL);
+    da = FcStrBuildFilename (rootdir, "conf.avail", "00-foo.conf", NULL);
+    cfg = FcConfigCreate ();
+    d = FcConfigRealFilename (cfg, dc);
+    if (strcmp ((const char *)d, (const char *)da) != 0)
+    {
+	fprintf (stderr, "E: failed to compare for non-sysroot: %s, %s\n", d, da);
+	goto bail;
+    }
+
+    free (d);
+    setenv ("FONTCONFIG_SYSROOT", sysroot, 1);
+    dsa = FcStrBuildFilename (sysroot, da, NULL);
+    dsac = FcStrCanonFilename (dsa);
+    d = FcConfigRealFilename (cfg, dc);
+    if (strcmp ((const char *)d, (const char *)dsac) != 0)
+    {
+	fprintf (stderr, "E: failed to compare for sysroot: %s, %s\n", d, dsac);
+	goto bail;
+    }
+
+    ret = 0;
+bail:
+    if (cfg)
+	FcConfigDestroy (cfg);
+    if (ds)
+	free (ds);
+    if (dsa)
+	free (dsa);
+    if (dsac)
+	free (dsac);
+    if (dc)
+	free (dc);
+    if (da)
+	free (da);
+    if (d)
+	free (d);
+    teardown (sysroot);
+    teardown (rootdir);
+
+    return ret;
+}
commit 806fd4c2c5164d66d978b0a4c579c157e5cbe766
Author: Akira TAGOH <akira@xxxxxxxxx>
Date:   Tue Sep 4 09:08:37 2018 +0000

    Fix the issue that '~' wasn't extracted to the proper homedir
    
    '~' in the filename was extracted to the home directory name in FcConfigFilename() though,
    this behavior was broken by d1f48f11. this change fixes it back to the correct behavior.
    
    https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/110

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e3ee1a8..6d356ae 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,7 +8,7 @@ before_script:
   - dnf -y upgrade --disablerepo=rawhide-modular
   - dnf -y install --disablerepo=rawhide-modular @buildsys-build autoconf automake libtool gettext gettext-devel gperf expat-devel freetype-devel libuuid-devel json-c-devel git docbook-utils docbook-utils-pdf
 
-build:
+shared-build:
   stage: build
   script:
     - export BUILD_ID="fontconfig-$CI_JOB_NAME_$CI_COMMIT_SHA-$CI_JOB_ID"
@@ -17,7 +17,7 @@ build:
     - export MAKEFLAGS="-j4"
     - mkdir "$BUILDDIR" "$PREFIX"
     - cd "$BUILDDIR"
-    - ../autogen.sh --prefix="$PREFIX"
+    - ../autogen.sh --prefix="$PREFIX" --enable-shared --disable-static
     - make
     - make check
     - make install
@@ -32,3 +32,22 @@ build:
       - build-*/fontconfig*/_build/sub/test/*.trs
       - build-*/*.log
       - prefix-*
+static-build:
+  stage: build
+  script:
+    - export BUILD_ID="fontconfig-$CI_JOB_NAME_$CI_COMMIT_SHA-$CI_JOB_ID"
+    - export PREFIX="$(pwd)/prefix-$BUILD_ID"
+    - export BUILDDIR="$(pwd)/build-$BUILD_ID"
+    - export MAKEFLAGS="-j4"
+    - mkdir "$BUILDDIR"
+    - cd "$BUILDDIR"
+    - ../autogen.sh --prefix="$PREFIX" --disable-shared --enable-static
+    - make
+    - make check
+  artifacts:
+    name: fontconfig-$CI_COMMIT_SHA-$CI_JOB_ID
+    when: always
+    paths:
+      - build-*/*.log
+      - build-*/test/*.log
+      - build-*/test/*.trs
diff --git a/src/fccfg.c b/src/fccfg.c
index d7c48e8..4a53581 100644
--- a/src/fccfg.c
+++ b/src/fccfg.c
@@ -2207,17 +2207,19 @@ FcConfigFilename (const FcChar8 *url)
 	else
 	    file = 0;
     }
-
-    path = FcConfigGetPath ();
-    if (!path)
-	return NULL;
-    for (p = path; *p; p++)
+    else
     {
-	file = FcConfigFileExists (*p, url);
-	if (file)
-	    break;
+	path = FcConfigGetPath ();
+	if (!path)
+	    return NULL;
+	for (p = path; *p; p++)
+	{
+	    file = FcConfigFileExists (*p, url);
+	    if (file)
+		break;
+	}
+	FcConfigFreePath (path);
     }
-    FcConfigFreePath (path);
     return file;
 }
 
diff --git a/test/Makefile.am b/test/Makefile.am
index 79bcede..9f4d48a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -91,6 +91,22 @@ test_bz106632_CFLAGS =					\
 test_bz106632_LDADD = $(top_builddir)/src/libfontconfig.la
 TESTS += test-bz106632
 
+if !ENABLE_SHARED
+check_PROGRAMS += test-issue110
+test_issue110_CFLAGS =					\
+	-I$(top_builddir)				\
+	-I$(top_builddir)/src				\
+	-I$(top_srcdir)					\
+	-I$(top_srcdir)/src				\
+	-DHAVE_CONFIG_H					\
+	-DFONTCONFIG_PATH='"$(BASECONFIGDIR)"'		\
+	$(NULL)
+test_issue110_LDADD =					\
+	$(top_builddir)/src/libfontconfig.la		\
+	$(NULL)
+TESTS += test-issue110
+endif
+
 EXTRA_DIST=run-test.sh run-test-conf.sh $(TESTDATA) out.expected-long-family-names out.expected-no-long-family-names
 
 CLEANFILES=out out1 out2 fonts.conf out.expected
diff --git a/test/test-issue110.c b/test/test-issue110.c
new file mode 100644
index 0000000..28a3bd2
--- /dev/null
+++ b/test/test-issue110.c
@@ -0,0 +1,245 @@
+/*
+ * fontconfig/test/test-issue110.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/fc110-XXXXXX";
+    char *sysroot, systempl[512] = "/tmp/fc110-XXXXXX";
+    FcChar8 *d = NULL;
+    FcChar8 *ret = NULL;
+    FcChar8 *s = NULL;
+    FILE *fp;
+    int retval = 0;
+
+    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;
+    }
+    fprintf (stderr, "D: Creating %s\n", basedir);
+    mkdir_p (basedir);
+    setenv ("HOME", basedir, 1);
+    retval++;
+    s = FcStrBuildFilename (basedir, ".fonts.conf", NULL);
+    if (!s)
+	goto bail;
+    retval++;
+    fprintf (stderr, "D: Creating %s\n", s);
+    if ((fp = fopen (s, "wb")) == NULL)
+	goto bail;
+    fprintf (fp, "%s", s);
+    fclose (fp);
+    retval++;
+    fprintf (stderr, "D: Checking file path\n");
+    ret = FcConfigRealFilename (cfg, "~/.fonts.conf");
+    if (!ret)
+	goto bail;
+    retval++;
+    if (strcmp ((const char *) s, (const char *) ret) != 0)
+	goto bail;
+    free (ret);
+    free (s);
+    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);
+    s = FcStrBuildFilename (sysroot, basedir, ".fonts.conf", NULL);
+    if (!s)
+	goto bail;
+    retval++;
+    fprintf (stderr, "D: Creating %s\n", s);
+    if ((fp = fopen (s, "wb")) == NULL)
+	goto bail;
+    fprintf (fp, "%s", s);
+    fclose (fp);
+    retval++;
+    fprintf (stderr, "D: Checking file path\n");
+    ret = FcConfigRealFilename (cfg, "~/.fonts.conf");
+    if (!ret)
+	goto bail;
+    retval++;
+    if (strcmp ((const char *) s, (const char *) ret) != 0)
+	goto bail;
+    retval = 0;
+bail:
+    fprintf (stderr, "Cleaning up\n");
+    unlink_dirs (basedir);
+    if (ret)
+	free (ret);
+    if (s)
+	free (s);
+
+    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