Gitweb links:

...log 
http://git.netsurf-browser.org/librufl.git/shortlog/6dce21aa10a2d5f5a745a2f168d801d4baa7d4b2
...commit 
http://git.netsurf-browser.org/librufl.git/commit/6dce21aa10a2d5f5a745a2f168d801d4baa7d4b2
...tree 
http://git.netsurf-browser.org/librufl.git/tree/6dce21aa10a2d5f5a745a2f168d801d4baa7d4b2

The branch, jmb/ac has been updated
       via  6dce21aa10a2d5f5a745a2f168d801d4baa7d4b2 (commit)
      from  a1389acbc6234340c14f9236bfc9b6fd1776e8d8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/librufl.git/commit/?id=6dce21aa10a2d5f5a745a2f168d801d4baa7d4b2
commit 6dce21aa10a2d5f5a745a2f168d801d4baa7d4b2
Author: John-Mark Bell <[email protected]>
Commit: John-Mark Bell <[email protected]>

    Use version-specific cache location.
    
    Move the cache location to a subdirectory within Scrap and encode
    the cache version in the filename.
    
    This allows software using different versions of RUfl to coexist
    on the same system without trying to share the same cache (and
    thus rescanning fonts every time).

diff --git a/src/rufl_init.c b/src/rufl_init.c
index 25753d6..6ec21b7 100644
--- a/src/rufl_init.c
+++ b/src/rufl_init.c
@@ -14,6 +14,8 @@
 #include <string.h>
 #include <strings.h>
 #include <search.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <oslib/font.h>
 #include <oslib/hourglass.h>
 #include <oslib/os.h>
@@ -1329,6 +1331,52 @@ int rufl_unicode_map_cmp(const void *z1, const void *z2)
 }
 
 
+static FILE *rufl_open_cache(const char *mode)
+{
+       const unsigned int version = rufl_CACHE_VERSION;
+       size_t len;
+       FILE *fp;
+       char fn[PATH_MAX];
+
+       if (!mode)
+               return NULL;
+
+       strcpy(fn, rufl_CACHE_TEMPLATE);
+       len = strlen(fn);
+
+       /* Fill in version suffix */
+       fn[len-4] = "0123456789abcdef"[(version>>12) & 0xf];
+       fn[len-3] = "0123456789abcdef"[(version>> 8) & 0xf];
+       fn[len-2] = "0123456789abcdef"[(version>> 4) & 0xf];
+       fn[len-1] = "0123456789abcdef"[version & 0xf];
+
+       if (mode[0] == 'a' || mode[0] == 'w') {
+               /* Wind back to directory separator */
+               while (len > 0 && fn[len] != '.')
+                       len--;
+               if (len == 0) {
+                       LOG("%s", "Malformed cache location");
+                       return NULL;
+               }
+
+               /* Ensure directory exists */
+               fn[len] = '\0';
+               if (mkdir(fn, 0755) == -1 && errno != EEXIST) {
+                       LOG("mkdir: 0x%x: %s", errno, strerror(errno));
+                       return NULL;
+               }
+               fn[len] = '.';
+       }
+
+       fp = fopen(fn, mode);
+       if (!fp) {
+               LOG("fopen: 0x%x: %s", errno, strerror(errno));
+               return NULL;;
+       }
+
+       return fp;
+}
+
 /**
  * Save character sets to cache.
  */
@@ -1340,11 +1388,9 @@ rufl_code rufl_save_cache(void)
        size_t len;
        FILE *fp;
 
-       fp = fopen(rufl_CACHE, "wb");
-       if (!fp) {
-               LOG("fopen: 0x%x: %s", errno, strerror(errno));
+       fp = rufl_open_cache("wb");
+       if (!fp)
                return rufl_OK;
-       }
 
        /* cache format version */
        if (fwrite(&version, sizeof version, 1, fp) != 1) {
@@ -1494,11 +1540,9 @@ rufl_code rufl_load_cache(void)
        struct rufl_unicode_map *umap = NULL;
        unsigned int num_umaps = 0;
 
-       fp = fopen(rufl_CACHE, "rb");
-       if (!fp) {
-               LOG("fopen: 0x%x: %s", errno, strerror(errno));
+       fp = rufl_open_cache("rb");
+       if (!fp)
                return rufl_OK;
-       }
 
        /* cache format version */
        if (fread(&version, sizeof version, 1, fp) != 1) {
diff --git a/src/rufl_internal.h b/src/rufl_internal.h
index 6cf6b14..42f0def 100644
--- a/src/rufl_internal.h
+++ b/src/rufl_internal.h
@@ -235,7 +235,7 @@ void rufl_substitution_table_dump(void);
                u = 0xfffd;                                                    \
        }
 
-#define rufl_CACHE "<Wimp$ScrapDir>.RUfl_cache"
+#define rufl_CACHE_TEMPLATE "<Wimp$ScrapDir>.RUfl.CacheNNNN"
 #define rufl_CACHE_VERSION 4
 
 


-----------------------------------------------------------------------

Summary of changes:
 src/rufl_init.c     |   60 ++++++++++++++++++++++++++++++++++++++++++++-------
 src/rufl_internal.h |    2 +-
 2 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/src/rufl_init.c b/src/rufl_init.c
index 25753d6..6ec21b7 100644
--- a/src/rufl_init.c
+++ b/src/rufl_init.c
@@ -14,6 +14,8 @@
 #include <string.h>
 #include <strings.h>
 #include <search.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <oslib/font.h>
 #include <oslib/hourglass.h>
 #include <oslib/os.h>
@@ -1329,6 +1331,52 @@ int rufl_unicode_map_cmp(const void *z1, const void *z2)
 }
 
 
+static FILE *rufl_open_cache(const char *mode)
+{
+       const unsigned int version = rufl_CACHE_VERSION;
+       size_t len;
+       FILE *fp;
+       char fn[PATH_MAX];
+
+       if (!mode)
+               return NULL;
+
+       strcpy(fn, rufl_CACHE_TEMPLATE);
+       len = strlen(fn);
+
+       /* Fill in version suffix */
+       fn[len-4] = "0123456789abcdef"[(version>>12) & 0xf];
+       fn[len-3] = "0123456789abcdef"[(version>> 8) & 0xf];
+       fn[len-2] = "0123456789abcdef"[(version>> 4) & 0xf];
+       fn[len-1] = "0123456789abcdef"[version & 0xf];
+
+       if (mode[0] == 'a' || mode[0] == 'w') {
+               /* Wind back to directory separator */
+               while (len > 0 && fn[len] != '.')
+                       len--;
+               if (len == 0) {
+                       LOG("%s", "Malformed cache location");
+                       return NULL;
+               }
+
+               /* Ensure directory exists */
+               fn[len] = '\0';
+               if (mkdir(fn, 0755) == -1 && errno != EEXIST) {
+                       LOG("mkdir: 0x%x: %s", errno, strerror(errno));
+                       return NULL;
+               }
+               fn[len] = '.';
+       }
+
+       fp = fopen(fn, mode);
+       if (!fp) {
+               LOG("fopen: 0x%x: %s", errno, strerror(errno));
+               return NULL;;
+       }
+
+       return fp;
+}
+
 /**
  * Save character sets to cache.
  */
@@ -1340,11 +1388,9 @@ rufl_code rufl_save_cache(void)
        size_t len;
        FILE *fp;
 
-       fp = fopen(rufl_CACHE, "wb");
-       if (!fp) {
-               LOG("fopen: 0x%x: %s", errno, strerror(errno));
+       fp = rufl_open_cache("wb");
+       if (!fp)
                return rufl_OK;
-       }
 
        /* cache format version */
        if (fwrite(&version, sizeof version, 1, fp) != 1) {
@@ -1494,11 +1540,9 @@ rufl_code rufl_load_cache(void)
        struct rufl_unicode_map *umap = NULL;
        unsigned int num_umaps = 0;
 
-       fp = fopen(rufl_CACHE, "rb");
-       if (!fp) {
-               LOG("fopen: 0x%x: %s", errno, strerror(errno));
+       fp = rufl_open_cache("rb");
+       if (!fp)
                return rufl_OK;
-       }
 
        /* cache format version */
        if (fread(&version, sizeof version, 1, fp) != 1) {
diff --git a/src/rufl_internal.h b/src/rufl_internal.h
index 6cf6b14..42f0def 100644
--- a/src/rufl_internal.h
+++ b/src/rufl_internal.h
@@ -235,7 +235,7 @@ void rufl_substitution_table_dump(void);
                u = 0xfffd;                                                    \
        }
 
-#define rufl_CACHE "<Wimp$ScrapDir>.RUfl_cache"
+#define rufl_CACHE_TEMPLATE "<Wimp$ScrapDir>.RUfl.CacheNNNN"
 #define rufl_CACHE_VERSION 4
 
 


-- 
RISC OS Unicode Font Library
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to