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'},
{
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 <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"
#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 <root> change to <root> 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");
#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> (root) change to <root> 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");
continue;
}
- if (stat ((char *) dir, &statb) == -1)
+ if (FcStat (config, dir, &statb) == -1)
{
switch (errno) {
case ENOENT:
{
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)))
{
break;
}
remove = FcFalse;
- cache = FcDirCacheLoadFile (file_name, NULL);
+ cache = FcDirCacheLoadFile2 (file_name, config, NULL);
if (!cache)
{
if (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",
}
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;
}
FcBool really_force = FcFalse;
FcBool systemOnly = FcFalse;
FcConfig *config;
+ const char *rootDir;
int i;
int changed;
int ret;
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) {
case 'f':
force = FcTrue;
break;
+ case 'R':
+ rootDir = optarg;
+ break;
case 's':
systemOnly = FcTrue;
break;
return 1;
}
FcConfigSetCurrent (config);
+ FcConfigSetRoot (config, (const FcChar8 *) rootDir);
if (argv[i])
{