summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkira TAGOH <akira@tagoh.org>2013-08-07 11:57:19 +0900
committerAkira TAGOH <akira@tagoh.org>2013-08-07 12:05:32 +0900
commit041deb0cc541692e260b93232b9957c2538e3bb9 (patch)
treeb8151bce3cef04e14d087e6b64ab83bf2e42ec81 /src
parentd52daa0024a6c0bb160c3b3c7f85d0b031f88c85 (diff)
warn deprecated only when migration failed
Diffstat (limited to 'src')
-rw-r--r--src/fccache.c28
-rw-r--r--src/fccompat.c27
-rw-r--r--src/fcdir.c10
-rw-r--r--src/fcint.h6
-rw-r--r--src/fcxml.c59
5 files changed, 101 insertions, 29 deletions
diff --git a/src/fccache.c b/src/fccache.c
index 9f1c2982..e02d49e8 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -830,34 +830,6 @@ bail1:
return NULL;
}
-
-#ifdef _WIN32
-#include <direct.h>
-#define mkdir(path,mode) _mkdir(path)
-#endif
-
-static FcBool
-FcMakeDirectory (const FcChar8 *dir)
-{
- FcChar8 *parent;
- FcBool ret;
-
- if (strlen ((char *) dir) == 0)
- return FcFalse;
-
- parent = FcStrDirname (dir);
- if (!parent)
- return FcFalse;
- if (access ((char *) parent, F_OK) == 0)
- ret = mkdir ((char *) dir, 0755) == 0 && chmod ((char *) dir, 0755) == 0;
- else if (access ((char *) parent, F_OK) == -1)
- ret = FcMakeDirectory (parent) && (mkdir ((char *) dir, 0755) == 0) && chmod ((char *) dir, 0755) == 0;
- else
- ret = FcFalse;
- FcStrFree (parent);
- return ret;
-}
-
/* write serialized state to the cache file */
FcBool
FcDirCacheWrite (FcCache *cache, FcConfig *config)
diff --git a/src/fccompat.c b/src/fccompat.c
index a2171607..d4f88c83 100644
--- a/src/fccompat.c
+++ b/src/fccompat.c
@@ -219,3 +219,30 @@ FcRandom(void)
return result;
}
+
+#ifdef _WIN32
+#include <direct.h>
+#define mkdir(path,mode) _mkdir(path)
+#endif
+
+FcBool
+FcMakeDirectory (const FcChar8 *dir)
+{
+ FcChar8 *parent;
+ FcBool ret;
+
+ if (strlen ((char *) dir) == 0)
+ return FcFalse;
+
+ parent = FcStrDirname (dir);
+ if (!parent)
+ return FcFalse;
+ if (access ((char *) parent, F_OK) == 0)
+ ret = mkdir ((char *) dir, 0755) == 0 && chmod ((char *) dir, 0755) == 0;
+ else if (access ((char *) parent, F_OK) == -1)
+ ret = FcMakeDirectory (parent) && (mkdir ((char *) dir, 0755) == 0) && chmod ((char *) dir, 0755) == 0;
+ else
+ ret = FcFalse;
+ FcStrFree (parent);
+ return ret;
+}
diff --git a/src/fcdir.c b/src/fcdir.c
index dc580bb6..b040a285 100644
--- a/src/fcdir.c
+++ b/src/fcdir.c
@@ -49,6 +49,16 @@ FcFileIsLink (const FcChar8 *file)
#endif
}
+FcBool
+FcFileIsFile (const FcChar8 *file)
+{
+ struct stat statb;
+
+ if (FcStat (file, &statb) != 0)
+ return FcFalse;
+ return S_ISREG (statb.st_mode);
+}
+
static FcBool
FcFileScanFontConfig (FcFontSet *set,
FcBlanks *blanks,
diff --git a/src/fcint.h b/src/fcint.h
index 52c47a12..ec0c6747 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -747,6 +747,9 @@ FcMakeTempfile (char *template);
FcPrivate int32_t
FcRandom (void);
+FcPrivate FcBool
+FcMakeDirectory (const FcChar8 *dir);
+
/* fcdbg.c */
FcPrivate void
@@ -805,6 +808,9 @@ FcPrivate FcBool
FcFileIsLink (const FcChar8 *file);
FcPrivate FcBool
+FcFileIsFile (const FcChar8 *file);
+
+FcPrivate FcBool
FcFileScanConfig (FcFontSet *set,
FcStrSet *dirs,
FcBlanks *blanks,
diff --git a/src/fcxml.c b/src/fcxml.c
index 6a2af85e..2cdf0ad0 100644
--- a/src/fcxml.c
+++ b/src/fcxml.c
@@ -2182,6 +2182,8 @@ FcParseInclude (FcConfigParse *parse)
FcBool ignore_missing = FcFalse;
FcBool deprecated = FcFalse;
FcChar8 *prefix = NULL, *p;
+ static FcChar8 *userdir = NULL;
+ static FcChar8 *userconf = NULL;
s = FcStrBufDoneStatic (&parse->pstack->str);
if (!s)
@@ -2214,23 +2216,78 @@ FcParseInclude (FcConfigParse *parse)
memcpy (&prefix[plen + 1], s, dlen);
prefix[plen + 1 + dlen] = 0;
s = prefix;
+ if (FcFileIsDir (s))
+ {
+ userdir:
+ if (!userdir)
+ userdir = FcStrdup (s);
+ }
+ else if (FcFileIsFile (s))
+ {
+ userconf:
+ if (!userconf)
+ userconf = FcStrdup (s);
+ }
+ else
+ {
+ /* 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
+ goto userconf;
+ }
}
if (!FcConfigParseAndLoad (parse->config, s, !ignore_missing))
parse->error = FcTrue;
+#ifndef _WIN32
else
{
FcChar8 *filename;
+ static FcBool warn_conf = FcFalse, warn_confd = FcFalse;
filename = FcConfigFilename(s);
if (deprecated == FcTrue &&
filename != NULL &&
!FcFileIsLink (filename))
{
- FcConfigMessage (parse, FcSevereWarning, "reading configurations from %s is deprecated.", s);
+ if (FcFileIsDir (filename))
+ {
+ if (FcFileIsDir (userdir) ||
+ rename ((const char *)filename, (const char *)userdir) != 0 ||
+ symlink ((const char *)userdir, (const char *)filename) != 0)
+ {
+ if (!warn_confd)
+ {
+ FcConfigMessage (parse, FcSevereWarning, "reading configurations from %s is deprecated. please move it to %s manually", s, userdir);
+ warn_confd = FcTrue;
+ }
+ }
+ }
+ else
+ {
+ if (FcFileIsFile (userconf) ||
+ rename ((const char *)filename, (const char *)userconf) != 0 ||
+ symlink ((const char *)userconf, (const char *)filename) != 0)
+ {
+ if (!warn_conf)
+ {
+ FcConfigMessage (parse, FcSevereWarning, "reading configurations from %s is deprecated. please move it to %s manually", s, userconf);
+ warn_conf = FcTrue;
+ }
+ }
+ }
}
if(filename)
FcStrFree(filename);
}
+#endif
FcStrBufDestroy (&parse->pstack->str);
bail: