]> git.e2factory.org Git - e2factory.git/commitdiff
hash: Add hash_file_once() which does all the hash context work
authorTobias Ulmer <tu@emlix.com>
Fri, 6 Dec 2013 17:53:17 +0000 (18:53 +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>
generic/hash.lua

index 8a119b8ee2a308ee37008ae00abbeecac017e07e..5172f1b982919c273f8357817bcbef5d93f84900 100644 (file)
@@ -127,6 +127,27 @@ function hash.hash_file(hc, path)
     return true
 end
 
+--- Hash a file at once.
+-- @param path Full path to the file.
+-- @return Checksum string, or false on error.
+-- @return Error object on failure.
+function hash.hash_file_once(path)
+    local rc, re, hc, cs
+
+    hc, re = hash.hash_start()
+    if not hc then
+        return false, re
+    end
+
+    rc, re = hash.hash_file(hc, path)
+    if not rc then
+        hash.hash_finish(hc)
+        return false, re
+    end
+
+    return hash.hash_finish(hc)
+end
+
 --- Get checksum and release hash context.
 -- @param hc the hash context
 -- @return SHA1 Checksum, or false on error.