- int ret = 0;
- FcChar8 *dir;
- FcStrSet *subdirs;
- FcStrList *sublist;
- struct stat statb;
- FcGlobalCacheDir *d;
-
- /*
- * Read in the results from 'list'.
- */
- while ((dir = FcStrListNext (list)))
- {
- if (!FcConfigAcceptFilename (config, dir))
- continue;
-
- /* Skip this directory if already updated
- * to avoid the looped directories via symlinks
- * Clearly a dir not in fonts.conf shouldn't be globally cached.
- */
- dir = (FcChar8 *)FcConfigNormalizeFontDir (config, dir);
- if (!dir)
- continue;
-
- if (FcStrSetMember (processed_dirs, dir))
- continue;
- if (!FcStrSetAdd (processed_dirs, dir))
- continue;
-
- subdirs = FcStrSetCreate ();
- if (!subdirs)
- {
- fprintf (stderr, "Can't create directory set\n");
- ret++;
- continue;
- }
-
- if (access ((char *) dir, X_OK) < 0)
- {
- switch (errno) {
- case ENOENT:
- case ENOTDIR:
- case EACCES:
- break;
- default:
- fprintf (stderr, "\"%s\": ", dir);
- perror ("");
- ret++;
- }
- FcStrSetDestroy (subdirs);
- continue;
- }
- if (stat ((char *) dir, &statb) == -1)
- {
- fprintf (stderr, "\"%s\": ", dir);
- perror ("");
- FcStrSetDestroy (subdirs);
- ret++;
- continue;
- }
- if (!S_ISDIR (statb.st_mode))
- {
- fprintf (stderr, "\"%s\": not a directory, skipping\n", dir);
- FcStrSetDestroy (subdirs);
- continue;
- }
- if (FcDirCacheValid (dir) && FcDirCacheRead (set, subdirs, dir, config))
- {
- /* if an old entry is found in the global cache, disable it */
- if ((d = FcGlobalCacheDirFind (cache, (const char *)dir)) != NULL)
- {
- d->state = FcGCDirDisabled;
- /* save the updated config later without this entry */
- cache->updated = FcTrue;
- }
- }
- else
- {
- if (FcDebug () & FC_DBG_FONTSET)
- printf ("cache scan dir %s\n", dir);
-
- FcDirScanConfig (set, subdirs, cache,
- config->blanks, dir, FcFalse, config);
- }
- sublist = FcStrListCreate (subdirs);
- FcStrSetDestroy (subdirs);
- if (!sublist)
- {
- fprintf (stderr, "Can't create subdir list in \"%s\"\n", dir);
- ret++;
- continue;
- }
- ret += FcCacheReadDirs (config, cache, sublist, set, processed_dirs);
- }
- FcStrListDone (list);