From f40886134d84fff0179165c04e20176d5cd1170d Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Tue, 29 Nov 2016 16:22:53 +0100 Subject: [PATCH] file_class: change the meaning of FileID to be inclusive of attributes This is a departure from the previous convention where fileid() returned the SHA1 sum of the file Signed-off-by: Tobias Ulmer --- local/chroot.lua | 2 -- local/e2tool.lua | 36 ++++++++++++++++++++++++++++++++---- local/licence.lua | 3 --- plugins/files.lua | 20 -------------------- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/local/chroot.lua b/local/chroot.lua index f5e7dac..a44c805 100644 --- a/local/chroot.lua +++ b/local/chroot.lua @@ -148,8 +148,6 @@ function chroot.chroot:chrootgroupid(info) local fileid for file in self:file_iter() do - hash.hash_append(hc, file:server()) - hash.hash_append(hc, file:location()) fileid, re = file:fileid() if not fileid then return false, e:cat(re) diff --git a/local/e2tool.lua b/local/e2tool.lua index 8b858c1..c63857d 100644 --- a/local/e2tool.lua +++ b/local/e2tool.lua @@ -126,7 +126,7 @@ function e2tool.file_class:_compute_fileid(flags) info = e2tool.info() - path, re = cache.fetch_file_path(info.cache, self:server(), self:location()) + path, re = cache.fetch_file_path(info.cache, self:server(), self:location(), flags) if not path then return false, re end @@ -139,8 +139,8 @@ function e2tool.file_class:_compute_fileid(flags) return fileid end ---- Calculate the FileID for a file. --- The name and location attributes are not included. +--- Calculate the FileID for a file. This includes the checksum of the file +-- as well as all set attributes. -- @return FileID string: hash value, or false on error. -- @return an error object on failure function e2tool.file_class:fileid() @@ -169,7 +169,35 @@ function e2tool.file_class:fileid() end end - return fileid + local hc, info + info = e2tool.info() + hc = hash.hash_start() + hash.hash_append(hc, self._server) + hash.hash_append(hc, self._location) + + hash.hash_append(hc, fileid) + + if self._licences then + local lid + + for licencename in self._licences:iter() do + local lid, re = licence.licences[licencename]:licenceid(info) + if not lid then + return false, e:cat(re) + end + hash.hash_append(hc, lid) + end + end + + if self._unpack then + hash.hash_append(hc, self._unpack) + elseif self._patch then + hash.hash_append(hc, self._patch) + elseif self._copy then + hash.hash_append(hc, self._copy) + end + + return hash.hash_finish(hc) end --- Set or return the server attribute. diff --git a/local/licence.lua b/local/licence.lua index dd9b612..fbfa060 100644 --- a/local/licence.lua +++ b/local/licence.lua @@ -125,9 +125,6 @@ function licence.licence:licenceid(info) hash.hash_append(hc, self._name) for file in self:file_iter() do - hash.hash_append(hc, file:server()) - hash.hash_append(hc, file:location()) - fileid, re = file:fileid() if not fileid then return false, e:cat(re) diff --git a/plugins/files.lua b/plugins/files.lua index 8d40f51..b7ae218 100644 --- a/plugins/files.lua +++ b/plugins/files.lua @@ -266,26 +266,6 @@ function files.files_source:sourceid(sourceset --[[always ignored for files]]) return false, re end hash.hash_append(hc, fileid) - hash.hash_append(hc, file:location()) - hash.hash_append(hc, file:server()) - if file:unpack() then - hash.hash_append(hc, file:unpack()) - elseif file:patch() then - hash.hash_append(hc, file:patch()) - elseif file:copy() then - hash.hash_append(hc, file:copy()) - else - assert(false, "no file attribute set") - end - - -- per file licence list - for licencename in file:licences():iter() do - local lid, re = licence.licences[licencename]:licenceid(info) - if not lid then - return false, re - end - hash.hash_append(hc, lid) - end end self._sourceid = hash.hash_finish(hc) -- 2.39.5