Changeset View
Changeset View
Standalone View
Standalone View
tools/pkgbase/metalog_reader.lua
Show First 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | function pkgname_from_tag(tagstr) | ||||
return pkgname | return pkgname | ||||
end | end | ||||
--- @class Analysis_session | --- @class Analysis_session | ||||
--- @param metalog string | --- @param metalog string | ||||
--- @param verbose boolean | --- @param verbose boolean | ||||
--- @param w_notagdirs boolean turn on to also check directories | --- @param w_notagdirs boolean turn on to also check directories | ||||
function Analysis_session(metalog, verbose, w_notagdirs) | function Analysis_session(metalog, verbose, w_notagdirs) | ||||
local stage_root = {} | |||||
local files = {} -- map<string, MetalogRow[]> | local files = {} -- map<string, MetalogRow[]> | ||||
-- set is map<elem, bool>. if bool is true then elem exists | -- set is map<elem, bool>. if bool is true then elem exists | ||||
local pkgs = {} -- map<string, set<string>> | local pkgs = {} -- map<string, set<string>> | ||||
----- used to keep track of files not belonging to a pkg. not used so | ----- used to keep track of files not belonging to a pkg. not used so | ||||
----- it is commented with ----- | ----- it is commented with ----- | ||||
-----local nopkg = {} -- set<string> | -----local nopkg = {} -- set<string> | ||||
--- @public | --- @public | ||||
local swarn = {} | local swarn = {} | ||||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | local function inode_report() | ||||
local inm = {} -- map<number, string[]> | local inm = {} -- map<number, string[]> | ||||
local unstatables = {} -- string[] | local unstatables = {} -- string[] | ||||
for filename in pairs(files) do | for filename in pairs(files) do | ||||
-- i only took the first row of a filename, | -- i only took the first row of a filename, | ||||
-- and skip links and folders | -- and skip links and folders | ||||
if files[filename][1].attrs.type ~= 'file' then | if files[filename][1].attrs.type ~= 'file' then | ||||
goto continue | goto continue | ||||
end | end | ||||
-- make ./xxx become /xxx so that we can stat | local fs = attributes(stage_root .. filename) | ||||
filename = filename:sub(2) | |||||
local fs = attributes(filename) | |||||
if fs == nil then | if fs == nil then | ||||
unstatables[#unstatables+1] = filename | unstatables[#unstatables+1] = filename | ||||
goto continue | goto continue | ||||
end | end | ||||
local inode = fs.ino | local inode = fs.ino | ||||
inm[inode] = inm[inode] or {} | inm[inode] = inm[inode] or {} | ||||
-- add back the dot prefix | table.insert(inm[inode], filename) | ||||
table.insert(inm[inode], '.'..filename) | |||||
::continue:: | ::continue:: | ||||
end | end | ||||
local warn, errs = {}, {} | local warn, errs = {}, {} | ||||
for _, filenames in pairs(inm) do | for _, filenames in pairs(inm) do | ||||
if #filenames == 1 then goto continue end | if #filenames == 1 then goto continue end | ||||
-- i only took the first row of a filename | -- i only took the first row of a filename | ||||
local rows = table_map(filenames, function(e) | local rows = table_map(filenames, function(e) | ||||
Show All 16 Lines | if #unstatables > 0 then | ||||
warn[#warn+1] = verbose and | warn[#warn+1] = verbose and | ||||
'note: skipped checking inodes: '..table.concat(unstatables, ',')..'\n' | 'note: skipped checking inodes: '..table.concat(unstatables, ',')..'\n' | ||||
or | or | ||||
'note: skipped checking inodes for '..#unstatables..' entries\n' | 'note: skipped checking inodes for '..#unstatables..' entries\n' | ||||
end | end | ||||
return table.concat(warn, ''), table.concat(errs, '') | return table.concat(warn, ''), table.concat(errs, '') | ||||
end | end | ||||
-- The METALOG file is assumed to be at the top of the stage directory. | |||||
stage_root = string.gsub(metalog, '/[^/]*$', '/') | |||||
do | do | ||||
local fp, errmsg, errcode = io.open(metalog, 'r') | local fp, errmsg, errcode = io.open(metalog, 'r') | ||||
if fp == nil then | if fp == nil then | ||||
io.stderr:write('cannot open '..metalog..': '..errmsg..': '..errcode..'\n') | io.stderr:write('cannot open '..metalog..': '..errmsg..': '..errcode..'\n') | ||||
os.exit(1) | os.exit(1) | ||||
end | end | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |