]> git.e2factory.org Git - e2factory.git/commitdiff
e2tool: move fileid() into file_class and adjust e2
authorTobias Ulmer <tu@emlix.com>
Mon, 28 Nov 2016 11:50:16 +0000 (12:50 +0100)
committerTobias Ulmer <tu@emlix.com>
Mon, 28 Nov 2016 11:50:16 +0000 (12:50 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
local/chroot.lua
local/e2tool.lua
local/licence.lua
local/project.lua
local/result.lua
plugins/files.lua

index 91381857a40a9c9d73ad6b3bc1ce853a1af238d4..f5e7dac2041a35dfc6b8de014db846ad544b56b3 100644 (file)
@@ -150,7 +150,7 @@ function chroot.chroot:chrootgroupid(info)
     for file in self:file_iter() do
         hash.hash_append(hc, file:server())
         hash.hash_append(hc, file:location())
-        fileid, re = e2tool.fileid(info, file)
+        fileid, re = file:fileid()
         if not fileid then
             return false, e:cat(re)
         end
index 7b35fdabc4c59c3df754bc321613326a6acfc636..704e976228a9b524933db51512e403b80eb1aa0d 100644 (file)
@@ -114,6 +114,61 @@ function e2tool.file_class:servloc()
     return self._server .. ":" .. self._location
 end
 
+--- Compute checksum of file by retreiving it via the cache transport,
+-- no matter the configuration what and hashing local.
+-- @return fileid on success, false if an error occured.
+-- @return error object on failure.
+function e2tool.file_class:_compute_fileid(flags)
+    local rc, re, info, path, fileid
+
+    info = e2tool.info()
+
+    path, re = cache.fetch_file_path(info.cache, self:server(), self:location())
+    if not path then
+        return false, re
+    end
+
+    fileid, re = hash.hash_file_once(path)
+    if not fileid then
+        return false, re
+    end
+
+    return fileid
+end
+
+--- Calculate the FileID for a file.
+-- The name and location attributes are not included.
+-- @return FileID string: hash value, or false on error.
+-- @return an error object on failure
+function e2tool.file_class:fileid()
+    local rc, re, e, fileid
+
+    e = err.new("error calculating file id for file: %s", self:servloc())
+
+    if self:sha1() then
+        fileid = self:sha1()
+    else
+        fileid, re = self:_compute_fileid(self)
+        if not fileid then
+            return false, e:cat(re)
+        end
+    end
+
+    if e2option.opts["check-remote"] then
+        local filever
+
+        filever = self:instance_copy()
+        filever:sha1(fileid)
+
+        rc, re = e2tool.verify_hash(e2tool.info(), filever)
+        if not rc then
+            return false, e:cat(re)
+        end
+    end
+
+    return fileid
+end
+
 --- Set or return the server attribute.
 -- Server name is any name known to cache.
 -- @param server Optional server name to set
@@ -953,45 +1008,6 @@ function e2tool.verify_hash(info, file)
     return false, e
 end
 
---- calculate a representation for file content. The name and location
--- attributes are not included.
--- @param info info table
--- @param file table: file table from configuration
--- @return fileid string: hash value, or false on error.
--- @return an error object on failure
-function e2tool.fileid(info, file)
-    assertIsTable(info)
-    assertIsTable(file)
-    assert(file:isInstanceOf(e2tool.file_class))
-
-    local rc, re, e, fileid
-
-    e = err.new("error calculating file id for file: %s", file:servloc())
-
-    if file:sha1() then
-        fileid = file:sha1()
-    else
-        fileid, re = compute_fileid(file)
-        if not fileid then
-            return false, e:cat(re)
-        end
-    end
-
-    if e2option.opts["check-remote"] then
-        local filever
-
-        filever = file:instance_copy()
-        filever:sha1(fileid)
-
-        rc, re = e2tool.verify_hash(info, filever)
-        if not rc then
-            return false, e:cat(re)
-        end
-    end
-
-    return fileid
-end
-
 --- select (mark) results based upon a list of results usually given on the
 -- command line. Parameters are assigned to all selected results.
 -- @param info the info structure
index 5d43077dd136bb7165b715802d5ecd82fc38d769..dd9b6129d21582778e41c32c6ead6d7b865ae5bd 100644 (file)
@@ -128,7 +128,7 @@ function licence.licence:licenceid(info)
         hash.hash_append(hc, file:server())
         hash.hash_append(hc, file:location())
 
-        fileid, re = e2tool.fileid(info, file)
+        fileid, re = file:fileid()
         if not fileid then
             return false, e:cat(re)
         end
index 63fe6337240b8c7ca8ac1a11b9defb9a62a83fe4..c34db318a7a957954817c34599556fbaf8ffd29e 100644 (file)
@@ -290,7 +290,7 @@ function project.projid(info)
         if not e2lib.is_backup_file(f) then
             location = e2lib.join("proj/init", f)
             file = e2tool.file_class:new(cache.server_names().dot, location)
-            fileid, re = e2tool.fileid(info, file)
+            fileid, re = file:fileid()
             if not fileid then
                 return false, re
             end
index d7ec61f0d3d40f9179b846bdfccdb68fb993a296..5ba529dd8d9d07e10c2ea5cff3b221d4f2fc16bc 100644 (file)
@@ -508,7 +508,7 @@ function result.result_class:buildid()
         e2tool.resultbuildscript(self:get_name_as_path())
         )
 
-    id, re = e2tool.fileid(info, file)
+    id, re = file:fileid()
     if not id then
         return false, re
     end
index 14db4ff86a27324d89a323b24b8e001e0086b350..8d40f5181a8e37cce8a07316fd24d3614aa04568 100644 (file)
@@ -261,7 +261,7 @@ function files.files_source:sourceid(sourceset --[[always ignored for files]])
     end
 
     for file in self:file_iter() do
-        local fileid, re = e2tool.fileid(info, file)
+        local fileid, re = file:fileid()
         if not fileid then
             return false, re
         end