glacier-ng 4.0.0

This commit is contained in:
lw-everestlinux committed 2026-10-29 09:15:34 -04:00
commit 0cf4829fa5
159 files changed
+33717

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
-- test_fs_tree.lua
--
-- gl_create_fs_tree: the top-level merged-/usr tree `syspkg -n` lays
-- down (decision GLACIER_BOOTSTRAP.txt 9d). Run against throwaway roots,
-- never "/": it must create exactly what's missing, with the right
-- types and modes, and leave anything already present untouched.
local glacier = require("glacier_ffi")
local h = require("test_helpers")
io.write("== test_fs_tree ==\n")
local function mkroot()
local p = io.popen("mktemp -d /tmp/fstree.XXXXXX")
local d = p:read("*l")
p:close()
return d
end
local function stat(path) -- "<type> <octal mode>" via busybox/coreutils stat
local p = io.popen("stat -c '%F %a' " .. h.quote(path) .. " 2>/dev/null")
local s = p:read("*l")
p:close()
return s
end
local function readlink(path)
local p = io.popen("readlink " .. h.quote(path) .. " 2>/dev/null")
local s = p:read("*l")
p:close()
return s
end
-- 1. Empty root: everything created, right type and mode.
local r = mkroot()
h.check(tonumber(glacier.lib.gl_create_fs_tree(r, false)) == 0, "create tree in an empty root")
local dirs = {
["/usr"] = "755", ["/usr/bin"] = "755", ["/usr/lib"] = "755",
["/etc"] = "755", ["/dev"] = "755", ["/proc"] = "555", ["/sys"] = "555",
["/run"] = "755", ["/tmp"] = "1777", ["/var"] = "755", ["/var/tmp"] = "1777",
["/root"] = "700", ["/home"] = "755",
}
for d, mode in pairs(dirs) do
h.check(stat(r .. d) == "directory " .. mode, d .. " is a directory, mode " .. mode)
end
local links = { ["/bin"] = "usr/bin", ["/sbin"] = "usr/bin", ["/lib"] = "usr/lib", ["/usr/sbin"] = "bin" }
for l, target in pairs(links) do
h.check(readlink(r .. l) == target, l .. " -> " .. target .. " (relative)")
end
-- Relative links resolve INSIDE the root, which is what makes them work
-- both under a prefix (syspkg --root) and once chrooted/booted:
-- musl's PT_INTERP /lib/ld-musl-*.so.1 -> /usr/lib/ld-musl-*.so.1.
h.sh("echo loader > " .. h.quote(r .. "/usr/lib/ld-test.so.1"))
h.check(h.exists(r .. "/lib/ld-test.so.1"), "/lib/x resolves to /usr/lib/x within the root")
h.sh("echo tool > " .. h.quote(r .. "/usr/bin/tool"))
h.check(h.exists(r .. "/sbin/tool") and h.exists(r .. "/usr/sbin/tool"),
"/sbin/x and /usr/sbin/x resolve to /usr/bin/x")
-- 2. Re-running is a no-op.
h.check(tonumber(glacier.lib.gl_create_fs_tree(r, false)) == 0, "second run succeeds")
h.check(stat(r .. "/tmp") == "directory 1777" and readlink(r .. "/bin") == "usr/bin",
"second run changed nothing")
-- 3. Existing entries of the "wrong" type are left exactly as they are.
local r2 = mkroot()
h.sh("mkdir " .. h.quote(r2 .. "/bin") .. " && echo keep > " .. h.quote(r2 .. "/bin/existing"))
h.sh("echo i-am-a-file > " .. h.quote(r2 .. "/tmp"))
h.sh("ln -s /elsewhere " .. h.quote(r2 .. "/lib"))
h.check(tonumber(glacier.lib.gl_create_fs_tree(r2 .. "/", false)) == 0,
"create tree over a partly-populated root (trailing slash on root)")
h.check(stat(r2 .. "/bin") == "directory 755" or (stat(r2 .. "/bin") or ""):match("^directory"),
"existing real /bin directory NOT replaced by a symlink")
h.check(h.exists(r2 .. "/bin/existing"), "its contents untouched")
h.check((stat(r2 .. "/tmp") or ""):match("^regular") ~= nil, "existing /tmp file left alone")
h.check(readlink(r2 .. "/lib") == "/elsewhere", "existing foreign /lib symlink left alone")
h.check(readlink(r2 .. "/sbin") == "usr/bin" and stat(r2 .. "/var/tmp") == "directory 1777",
"the missing entries were still created")
h.sh("rm -rf " .. h.quote(r) .. " " .. h.quote(r2))
h.summary()