70 lines
2.8 KiB
Lua
70 lines
2.8 KiB
Lua
-- test_relink_symlinks.lua
|
|
--
|
|
-- This is the regression test for the symlink-staleness bug: gl_link_pkg
|
|
-- used to run during a staged gl_install_pkg, embedding ctx->store_path
|
|
-- (the STAGE path) as the symlink target — which goes stale the instant
|
|
-- gl_commit_transaction renames the store into its live location.
|
|
--
|
|
-- The fix is two-part:
|
|
-- 1. gl_install_pkg only calls gl_link_pkg for a GL_CTX_LIVE context.
|
|
-- 2. gl_commit_transaction calls gl_relink_store(&live_ctx) after
|
|
-- promotion, regenerating the links tree from the (now real,
|
|
-- final) live store paths.
|
|
--
|
|
-- This test checks the raw (non-canonicalized) symlink target text
|
|
-- directly, since that's exactly what the original bug got wrong.
|
|
|
|
local glacier = require("glacier_ffi")
|
|
local h = require("test_helpers")
|
|
|
|
h.reset_glacier_root()
|
|
|
|
local uid = 1000
|
|
local pkg_name = "relinktest"
|
|
io.write("== test_relink_symlinks (uid " .. uid .. ") ==\n")
|
|
|
|
glacier.lib.gl_init_user(uid, false)
|
|
|
|
local stage = glacier.new_context()
|
|
local st = glacier.lib.gl_init_stage_context(stage, glacier.SCOPE_USR, uid)
|
|
if not h.check(tonumber(st) == 0, "gl_init_stage_context: " .. glacier.txn_name(st)) then
|
|
h.summary()
|
|
end
|
|
|
|
local pkgpath = h.build_fixture_pkg{ name = pkg_name, ver = "1.0.0", repo = "core" }
|
|
|
|
local inst = glacier.lib.gl_install_pkg(stage, pkgpath)
|
|
h.check(tonumber(inst) == 0,
|
|
"gl_install_pkg (staged): " .. glacier.install_name(inst))
|
|
|
|
-- Before commit: the live links tree must not have been touched at all,
|
|
-- since gl_link_pkg should have been skipped entirely for this stage ctx.
|
|
h.check(not h.exists("/glacier/usr/" .. uid .. "/links/bin/" .. pkg_name),
|
|
"no premature symlink exists in the live links tree before commit")
|
|
|
|
local commit = glacier.lib.gl_commit_transaction(stage)
|
|
h.check(tonumber(commit) == 0, "gl_commit_transaction: " .. glacier.txn_name(commit))
|
|
|
|
local link_path = "/glacier/usr/" .. uid .. "/links/bin/" .. pkg_name
|
|
h.check(h.exists(link_path), "symlink exists post-commit at " .. link_path)
|
|
|
|
local rl = io.popen("readlink " .. h.quote(link_path))
|
|
local raw_target = rl and rl:read("*l")
|
|
if rl then rl:close() end
|
|
|
|
h.check(raw_target ~= nil and raw_target:find("/glacier/usr/" .. uid .. "/store/", 1, true) == 1,
|
|
"raw symlink target embeds the LIVE store path: " .. tostring(raw_target))
|
|
h.check(raw_target ~= nil and not raw_target:find("/glacier/usr/" .. uid .. "/stage/", 1, true),
|
|
"raw symlink target does NOT embed the stage path")
|
|
|
|
local f = io.open(link_path, "r")
|
|
h.check(f ~= nil, "symlink target is actually readable through the link")
|
|
if f then
|
|
local data = f:read("*a")
|
|
f:close()
|
|
h.check(data == "hello from " .. pkg_name .. "\n",
|
|
"file content read through the symlink matches the fixture payload")
|
|
end
|
|
|
|
h.summary()
|