From: Tobias Ulmer Date: Fri, 6 Dec 2013 17:53:17 +0000 (+0100) Subject: hash: Add hash_file_once() which does all the hash context work X-Git-Tag: e2factory-2.3.15rc1~289 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=5e5e1cfb0bbec60c4b886bb37796d9caa2f41878;p=e2factory.git hash: Add hash_file_once() which does all the hash context work Signed-off-by: Tobias Ulmer --- diff --git a/generic/hash.lua b/generic/hash.lua index 8a119b8..5172f1b 100644 --- a/generic/hash.lua +++ b/generic/hash.lua @@ -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.