]> git.e2factory.org Git - e2factory.git/commitdiff
Use eio for writing hashcache
authorTobias Ulmer <tu@emlix.com>
Mon, 25 Nov 2013 13:13:03 +0000 (14:13 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:17 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
local/e2tool.lua

index e830946a7ba3c11dea40d1c13dc600bfc0099712..daab6f7bd00eaa50901f936ad21bbe615872a2ce 100644 (file)
@@ -1952,22 +1952,29 @@ local function projid(info)
     return info.projid
 end
 
---- hashcache write.
+--- Write out hashcache file.
+-- @param info Info table.
+-- @return True on success, false on error.
+-- @return Error object on failure.
 local function hashcache_write(info)
-    local e = err.new("writing hash cache file")
-    local f, msg = io.open(info.hashcache_file, "w")
-    if not f then
-        return false, e:append(msg)
-    end
-    f:write("return {\n")
+    local rc, re, e, out
+
+    out = { "return {\n" }
     for k,hce in pairs(info.hashcache) do
-        f:write(string.format(
-            "[%q] = { hash=%q, mtime=%d, mtime_nsec=%d, ctime=%d, ctime_nsec=%d, size=%d, dev=%d, ino=%d },\n",
+        table.insert(out, string.format(
+            "[%q] = { hash=%q, mtime=%d, mtime_nsec=%d, ctime=%d, " ..
+            "ctime_nsec=%d, size=%d, dev=%d, ino=%d },\n",
             k, hce.hash, hce.mtime, hce.mtime_nsec,
             hce.ctime, hce.ctime_nsec, hce.size, hce.dev, hce.ino))
     end
-    f:write("}\n")
-    f:close()
+    table.insert(out, "}\n")
+
+    rc, re = eio.file_write(info.hashcache_file, table.concat(out))
+    if not rc then
+        e = err.new("writing hash cache file")
+        return false, e:cat(re)
+    end
+
     return true
 end