OSDN Git Service

ltj-base.lua: remove uncompressed cache (.lua) automatically
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 4 Jul 2020 09:59:08 +0000 (18:59 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sat, 4 Jul 2020 09:59:13 +0000 (18:59 +0900)
src/ltj-base.lua

index d8a758e..574c201 100644 (file)
@@ -259,6 +259,18 @@ do
       if lfs.isdir(testpath) then savepath = testpath; break end
    end
    local serial_spec = {functions=false, noquotes=true}
+
+   local function remove_file_if_exist(name)
+     if os.rename(name,name) then os.remove(name) end
+   end
+   local function remove_cache (filename)
+      local fullpath_wo_ext = savepath .. '/' ..  filename .. '.lu'
+      remove_file_if_exist(fullpath_wo_ext .. 'a')
+      remove_file_if_exist(fullpath_wo_ext .. 'a.gz')
+      remove_file_if_exist(fullpath_wo_ext .. 'b')
+      remove_file_if_exist(fullpath_wo_ext .. 'c')
+   end
+
    local function save_cache_luc(filename, t, serialized)
       local fullpath = savepath .. '/' ..  filename .. luc_suffix
       local s = serialized or serialize(t, 'return', false, serial_spec)
@@ -306,6 +318,7 @@ do
    end
    
    local function load_cache(filename, outdate)
+      remove_file_if_exist(savepath .. '/' ..  filename .. '.lua')
       local r = load_cache_a(filename ..  luc_suffix, outdate, false)
       if r then 
         return r
@@ -316,17 +329,6 @@ do
       end
    end
 
-   local function remove_file_if_exist(name)
-     if os.rename(name,name) then os.remove(name) end
-   end
-   local function remove_cache (filename)
-      local fullpath_wo_ext = savepath .. '/' ..  filename .. '.lu'
-      remove_file_if_exist(fullpath_wo_ext .. 'a')
-      remove_file_if_exist(fullpath_wo_ext .. 'a.gz')
-      remove_file_if_exist(fullpath_wo_ext .. 'b')
-      remove_file_if_exist(fullpath_wo_ext .. 'c')
-   end
-
    ltjb.remove_cache = remove_cache
    ltjb.load_cache = load_cache
    ltjb.save_cache_luc = save_cache_luc