From d300342332aabd067ccd00396acb9d46df53a712 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Thu, 2 Aug 2012 17:29:17 +0200 Subject: [PATCH] Remove defect call to sha1sum and replace it with hash_file() Signed-off-by: Tobias Ulmer --- local/e2tool.lua | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/local/e2tool.lua b/local/e2tool.lua index bfe05b9..70b79e4 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -1005,20 +1005,19 @@ end -- @return string the hash value, nil on error -- @return nil, an error string on error function hash_path(path) - local f = io.popen(string.format("sha1sum %s", e2lib.shquote(path)), "r") - if not f then - return false, "can't calculation checksum" - end - local l = f:read("*l") - f:close() - if not l then - return nil, "can't calculation checksum" - end - local s, e, cs, b = string.find(l, "^(%S+)%s+(%S+)$") - if not cs then - return nil, "can't calculation checksum" + assert(type(path) == "string") + assert(string.len(path) > 0) + + local e = new_error("error hashing path") + + local ctx = hash.hash_start() + + local rc, re = ctx:hash_file(path) + if not rc then + return nil, e:cat(re) end - return cs + + return ctx:hash_finish() end --- hash a file addressed by server name and location -- 2.39.5