[latex3-commits] [latex3/luaotfload] dev: Use format for removing temporary files not reling on global temp dir (a5dc9f0a)

github at latex-project.org github at latex-project.org
Sat Feb 17 22:14:55 CET 2024


Repository : https://github.com/latex3/luaotfload
On branch  : dev
Link       : https://github.com/latex3/luaotfload/commit/a5dc9f0abefe323a6dfbb6b17ce805caa7aa1747

>---------------------------------------------------------------

commit a5dc9f0abefe323a6dfbb6b17ce805caa7aa1747
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Sat Feb 17 22:14:55 2024 +0100

    Use format for removing temporary files not reling on global temp dir


>---------------------------------------------------------------

a5dc9f0abefe323a6dfbb6b17ce805caa7aa1747
 src/luaotfload-harf-plug.lua | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/luaotfload-harf-plug.lua b/src/luaotfload-harf-plug.lua
index 93207030..e9ed7350 100644
--- a/src/luaotfload-harf-plug.lua
+++ b/src/luaotfload-harf-plug.lua
@@ -23,8 +23,10 @@ local format            = string.format
 local open              = io.open
 local tableinsert       = table.insert
 local tableremove       = table.remove
-local ostmpname         = os.tmpname
+local ostmpdir          = os.tmpdir
 local osremove          = os.remove
+local dir               = lfs.dir
+local rmdir             = lfs.rmdir
 
 local direct            = node.direct
 local tonode            = direct.tonode
@@ -704,13 +706,17 @@ end
 
 -- Cache of color glyph PNG data for bookkeeping, only because I couldn't
 -- figure how to make the engine load the image from the binary data directly.
+local tmpdirname
+local tmpcount = 0
 local pngcache = {}
 local pngcachefiles = {}
 local function cachedpng(data)
   local hash = md5.sumhexa(data)
   local i = pngcache[hash]
   if not i then
-    local path = ostmpname()
+    tmpdirname = tmpdirname or ostmpdir()
+    tmpcount = tmpcount + 1
+    local path = format('%s/%i.png', tmpdirname, tmpcount)
     pngcachefiles[#pngcachefiles + 1] = path
     open(path, "wb"):write(data):close()
     -- local file = open(path, "wb"):write():close()
@@ -1106,9 +1112,14 @@ end
 local function run_cleanup()
   -- Remove temporary PNG files that we created, if any.
   -- FIXME: It would be nice if we wouldn't need this
-  for _, path in next, pngcachefiles do
-    osremove(path)
+  if not tmpdirname then return end
+  for file in dir(tmpdirname) do
+    if file ~= '.' and file ~= '..' then
+      assert(osremove(format('%s/%s', tmpdirname, file)))
+    end
   end
+  assert(rmdir(tmpdirname))
+  tmpdirname = nil
 end
 
 local function set_tounicode()





More information about the latex3-commits mailing list.