X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=fc-cache%2Ffc-cache.c;fp=fc-cache%2Ffc-cache.c;h=59a24bbb324e5c98dfc1e1de3a686125395ff055;hb=d0471dd2faca37f7ee5997ad9db8278db0e99206;hp=98039f77ff778aaa1fd583bf5e066b42c195b0bf;hpb=bb8057ea77ec89e789afbc6e87b7a16d479d3105;p=fontconfig.git diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c index 98039f7..59a24bb 100644 --- a/fc-cache/fc-cache.c +++ b/fc-cache/fc-cache.c @@ -69,6 +69,7 @@ const struct option longopts[] = { {"force", 0, 0, 'f'}, {"really-force", 0, 0, 'r'}, + {"root", 1, 0, 'R'}, {"system-only", 0, 0, 's'}, {"version", 0, 0, 'V'}, {"verbose", 0, 0, 'v'}, @@ -87,10 +88,10 @@ usage (char *program, int error) { FILE *file = error ? stderr : stdout; #if HAVE_GETOPT_LONG - fprintf (file, "usage: %s [-frsvVh] [--force|--really-force] [--system-only] [--verbose] [--version] [--help] [dirs]\n", + fprintf (file, "usage: %s [-frRsvVh] [--force|--really-force] [--root ] [--system-only] [--verbose] [--version] [--help] [dirs]\n", program); #else - fprintf (file, "usage: %s [-frsvVh] [dirs]\n", + fprintf (file, "usage: %s [-frRsvVh] [dirs]\n", program); #endif fprintf (file, "Build font information caches in [dirs]\n" @@ -99,6 +100,7 @@ usage (char *program, int error) #if HAVE_GETOPT_LONG fprintf (file, " -f, --force scan directories with apparently valid caches\n"); fprintf (file, " -r, --really-force erase all existing caches, then rescan\n"); + fprintf (file, " -R, --root change to before loading files\n"); fprintf (file, " -s, --system-only scan system-wide directories only\n"); fprintf (file, " -v, --verbose display status information while busy\n"); fprintf (file, " -V, --version display font config version and exit\n"); @@ -106,6 +108,7 @@ usage (char *program, int error) #else fprintf (file, " -f (force) scan directories with apparently valid caches\n"); fprintf (file, " -r, (really force) erase all existing caches, then rescan\n"); + fprintf (file, " -R (root) change to before loading files\n"); fprintf (file, " -s (system) scan system-wide directories only\n"); fprintf (file, " -v (verbose) display status information while busy\n"); fprintf (file, " -V (version) display font config version and exit\n"); @@ -154,7 +157,7 @@ scanDirs (FcStrList *list, FcConfig *config, FcBool force, FcBool really_force, continue; } - if (stat ((char *) dir, &statb) == -1) + if (FcStat (config, dir, &statb) == -1) { switch (errno) { case ENOENT: @@ -253,25 +256,34 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose) { DIR *d; struct dirent *ent; + FcChar8 *fullDir; + FcChar8 *checkDir; FcBool ret = FcTrue; FcBool remove; FcCache *cache; struct stat target_stat; - if (access ((char *) dir, W_OK) != 0) + fullDir = FcConfigGetRootPlus (config, dir); + if (fullDir) + checkDir = fullDir; + else + checkDir = dir; + + if (access ((char *) checkDir, W_OK) != 0) { if (verbose) printf ("%s: not cleaning %s cache directory\n", dir, access ((char *) dir, F_OK) == 0 ? "unwritable" : "non-existent"); - return FcTrue; + goto done; } if (verbose) printf ("%s: cleaning cache directory\n", dir); - d = opendir ((char *) dir); + d = opendir ((char *) checkDir); if (!d) { perror ((char *) dir); - return FcFalse; + ret = FcFalse; + goto done; } while ((ent = readdir (d))) { @@ -294,7 +306,7 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose) break; } remove = FcFalse; - cache = FcDirCacheLoadFile (file_name, NULL); + cache = FcDirCacheLoadFile2 (file_name, config, NULL); if (!cache) { if (verbose) @@ -304,7 +316,7 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose) else { target_dir = FcCacheDir (cache); - if (stat ((char *) target_dir, &target_stat) < 0) + if (FcStat (config, target_dir, &target_stat) < 0) { if (verbose) printf ("%s: %s: missing directory: %s \n", @@ -314,17 +326,25 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose) } if (remove) { - if (unlink ((char *) file_name) < 0) + FcChar8 *unlink_file = FcConfigGetRootPlus (config, file_name); + if (!unlink_file) + unlink_file = file_name; + if (unlink ((char *) unlink_file) < 0) { - perror ((char *) file_name); + perror ((char *) unlink_file); ret = FcFalse; } + if (unlink_file != file_name) + FcStrFree (unlink_file); } FcDirCacheUnload (cache); FcStrFree (file_name); } closedir (d); + done: + if (fullDir) + FcStrFree (fullDir); return ret; } @@ -359,6 +379,7 @@ main (int argc, char **argv) FcBool really_force = FcFalse; FcBool systemOnly = FcFalse; FcConfig *config; + const char *rootDir; int i; int changed; int ret; @@ -366,9 +387,9 @@ main (int argc, char **argv) int c; #if HAVE_GETOPT_LONG - while ((c = getopt_long (argc, argv, "frsVvh", longopts, NULL)) != -1) + while ((c = getopt_long (argc, argv, "frR:sVvh", longopts, NULL)) != -1) #else - while ((c = getopt (argc, argv, "frsVvh")) != -1) + while ((c = getopt (argc, argv, "frR:sVvh")) != -1) #endif { switch (c) { @@ -378,6 +399,9 @@ main (int argc, char **argv) case 'f': force = FcTrue; break; + case 'R': + rootDir = optarg; + break; case 's': systemOnly = FcTrue; break; @@ -408,6 +432,7 @@ main (int argc, char **argv) return 1; } FcConfigSetCurrent (config); + FcConfigSetRoot (config, (const FcChar8 *) rootDir); if (argv[i]) {