From 0c7e35163064e7d40cddbad129745060d9666ee6 Mon Sep 17 00:00:00 2001
From: Philipp Gesang <phg42.2a@gmail.com>
Date: Fri, 14 Feb 2014 21:50:50 +0100
Subject: =?UTF-8?q?[db]=20add=20=E2=80=9Clocal=E2=80=9D=20field=20to=20met?=
 =?UTF-8?q?a=20table=20in=20db?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/luaotfload-database.lua | 35 ++++++++++++++++++++++-------------
 src/luaotfload-tool.lua     |  2 +-
 2 files changed, 23 insertions(+), 14 deletions(-)

(limited to 'src')

diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua
index 4b2d201..54474e2 100644
--- a/src/luaotfload-database.lua
+++ b/src/luaotfload-database.lua
@@ -140,7 +140,7 @@ luaotfloadconfig.compress      = luaotfloadconfig.compress ~= false
 local names                    = fonts.names
 local name_index               = nil --> upvalue for names.data
 local lookup_cache             = nil --> for names.lookups
-names.version                  = 2.5
+names.version                  = 2.51
 names.data                     = nil      --- contains the loaded database
 names.lookups                  = nil      --- contains the lookup cache
 
@@ -356,6 +356,7 @@ This is a sketch of the luaotfload db:
         optical : (int, int) list;  // design size -> index entry
     }
     and metadata = {
+        local       : bool;        (* set if local fonts were added to the db *)
         formats     : string list; // { "otf", "ttf", "ttc", "dfont" }
         statistics  : TODO;
         version     : float;
@@ -439,7 +440,9 @@ mtx-fonts has in names.tma:
 
 --doc]]--
 
-local initialize_namedata = function (formats) --- returns dbobj
+--- string list -> dbobj
+
+local initialize_namedata = function (formats)
     return {
         --families        = { },
         status          = { }, -- was: status; map abspath -> mapping
@@ -447,6 +450,7 @@ local initialize_namedata = function (formats) --- returns dbobj
         names           = { },
 --      files           = { }, -- created later
         meta            = {
+            ["local"]  = false,
             formats    = formats,
             statistics = { },
             version    = names.version,
@@ -2380,11 +2384,11 @@ local scan_os_fonts = function (currentnames,
     return n_scanned, n_new
 end
 
---- unit -> (bool, lookup_cache)
+--- unit -> bool
 flush_lookup_cache = function ()
     lookup_cache = { }
     collectgarbage "collect"
-    return true, lookup_cache
+    return true
 end
 
 
@@ -3164,16 +3168,16 @@ update_names = function (currentnames, force, dry_run)
 
     if dry_run ~= true then
 
-        save_names ()
+        local success, reason = save_names ()
+        if not success then
+            report ("both", 0, "db",
+                    "Failed to save database to disk: %s",
+                    reason)
+        end
 
-        local success, _lookups = flush_lookup_cache ()
-        if success then
-            local success = save_lookups ()
-            if success then
-                report ("info", 2, "cache",
-                                   "Lookup cache emptied.")
-                return targetnames
-            end
+        if flush_lookup_cache () and save_lookups () then
+            report ("both", 2, "cache", "Lookup cache emptied.")
+            return targetnames
         end
     end
     return targetnames
@@ -3211,6 +3215,11 @@ save_names = function (currentnames)
     if not currentnames then
         currentnames = name_index
     end
+    if not currentnames or type (currentnames) ~= "table" then
+        return false, "invalid names table"
+    elseif currentnames.meta and currentnames.meta["local"] then
+        return false, "table contains local entries"
+    end
     local path = names.path.index
     local luaname, lucname = path.lua, path.luc
     if fileiswritable (luaname) and fileiswritable (lucname) then
diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua
index 35765b5..01d0361 100755
--- a/src/luaotfload-tool.lua
+++ b/src/luaotfload-tool.lua
@@ -772,7 +772,7 @@ actions.generate = function (job)
 end
 
 actions.flush = function (job)
-    local success, lookups = names.flush_lookup_cache()
+    local success = names.flush_lookup_cache()
     if success then
         local success = names.save_lookups()
         if success then
-- 
cgit v1.2.3