return c
end
+--- translate filename suffixes to valid tartypes for e2-su-2.2
+-- @filename string: filename
+-- @return string: tartype, or nil on failure
+-- @return an error object on failure
+function e2lib.tartype_by_suffix(filename)
+ local tartype
+ if filename:match("tgz$") or filename:match("tar.gz$") then
+ tartype = "tar.gz"
+ elseif filename:match("tar.bz2$") then
+ tartype = "tar.bz2"
+ elseif filename:match("tar$") then
+ tartype = "tar"
+ else
+ e = new_error("unknown suffix for filename: %s", filename)
+ return false, e
+ end
+ return tartype
+end
+
-- generates a command to unpack an archive file
-- physpath is the current location and filename to be unpacked later
-- virtpath is the location and name of the file at the time of unpacking
end
end
local tartype
- if path:match("tgz$") or path:match("tar.gz$") then
- tartype = "tar.gz"
- elseif path:match("tar.bz2$") then
- tartype = "tar.bz2"
- elseif path:match("tar$") then
- tartype = "tar"
- else
- e:append("unknown archive type for chroot file: %s", path)
- return false, e
+ tartype, re = e2lib.tartype_by_suffix(path)
+ if not tartype then
+ return false, e:cat(re)
end
-- e2-su extract_tar_2_3 <path> <tartype> <file>
local args = string.format("extract_tar_2_3 '%s' '%s' '%s'",
"\tsha1sum -c '%s'\n",
e2lib.basename(checksum_file)))
end
+ local tartype
+ tartype, re = e2lib.tartype_by_suffix(file.location)
+ if not tartype then
+ return false, e:cat(re)
+ end
makefile:write(string.format(
"\te2-su-2.2 extract_tar_2_3 $(chroot_base) "..
- "\"tar.gz\" '%s'\n",
- e2lib.basename(file.location)))
+ "\"%s\" '%s'\n",
+ tartype, e2lib.basename(file.location)))
end
makefile:close()
end