]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccache.c
[doc] Fix typo
[fontconfig.git] / src / fccache.c
index c7a2dcdc0fbc9ca18654bcc06426e5dab45a6fac..69e1a6b82166532df55dff1957fb58901d5b9a1c 100644 (file)
@@ -12,9 +12,9 @@
  * representations about the suitability of this software for any purpose.  It
  * is provided "as is" without express or implied warranty.
  *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * 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
@@ -85,7 +85,7 @@ typedef __int64 INT64;
  * just use the UTC timestamps from NTFS, converted to the Unix epoch.
  */
 
-static int
+int
 FcStat (const char *file, struct stat *statb)
 {
     WIN32_FILE_ATTRIBUTE_DATA wfad;
@@ -131,11 +131,6 @@ FcStat (const char *file, struct stat *statb)
     
     return 0;
 }
-
-#else
-
-#define FcStat stat
-
 #endif
 
 static const char bin2hex[] = { '0', '1', '2', '3',
@@ -543,7 +538,13 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat, struct stat *dir_stat)
        return NULL;
     cache = FcCacheFindByStat (fd_stat);
     if (cache)
-       return cache;
+    {
+       if (FcCacheTimeValid (cache, dir_stat))
+           return cache;
+       FcDirCacheUnload (cache);
+       cache = NULL;
+    }
+
     /*
      * Lage cache files are mmap'ed, smaller cache files are read. This
      * balances the system cost of mmap against per-process memory usage.
@@ -552,6 +553,8 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat, struct stat *dir_stat)
     {
 #if defined(HAVE_MMAP) || defined(__CYGWIN__)
        cache = mmap (0, fd_stat->st_size, PROT_READ, MAP_SHARED, fd, 0);
+       if (cache == MAP_FAILED)
+           cache = NULL;
 #elif defined(_WIN32)
        {
            HANDLE hFileMap;
@@ -822,9 +825,9 @@ FcMakeDirectory (const FcChar8 *dir)
     if (!parent)
        return FcFalse;
     if (access ((char *) parent, F_OK) == 0)
-       ret = mkdir ((char *) dir, 0777) == 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, 0777) == 0);
+       ret = FcMakeDirectory (parent) && (mkdir ((char *) dir, 0755) == 0) && chmod ((char *) dir, 0755) == 0;
     else
        ret = FcFalse;
     FcStrFree (parent);
@@ -843,6 +846,8 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
     FcStrList      *list;
     FcChar8        *cache_dir = NULL;
     FcChar8        *test_dir;
+    FcCacheSkip     *skip;
+    struct stat     cache_stat;
     int                    magic;
     int                    written;
 
@@ -854,7 +859,7 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
     if (!list)
        return FcFalse;
     while ((test_dir = FcStrListNext (list))) {
-       if (access ((char *) test_dir, W_OK) == 0)
+       if (access ((char *) test_dir, W_OK|X_OK) == 0)
        {
            cache_dir = test_dir;
            break;
@@ -871,6 +876,14 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
                    break;
                }
            }
+           /*
+            * Otherwise, try making it writable
+            */
+           else if (chmod ((char *) test_dir, 0755) == 0)
+           {
+               cache_dir = test_dir;
+               break;
+           }
        }
     }
     FcStrListDone (list);
@@ -920,6 +933,20 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
     close(fd);
     if (!FcAtomicReplaceOrig(atomic))
         goto bail4;
+
+    /* If the file is small, update the cache chain entry such that the
+     * new cache file is not read again.  If it's large, we don't do that
+     * such that we reload it, using mmap, which is shared across processes.
+     */
+    if (cache->size < FC_CACHE_MIN_MMAP &&
+       (skip = FcCacheFindByAddr (cache)) &&
+       FcStat (cache_hashed, &cache_stat))
+    {
+       skip->cache_dev = cache_stat.st_dev;
+       skip->cache_ino = cache_stat.st_ino;
+       skip->cache_mtime = cache_stat.st_mtime;
+    }
+
     FcStrFree (cache_hashed);
     FcAtomicUnlock (atomic);
     FcAtomicDestroy (atomic);