54 lines
2.5 KiB
Lua
54 lines
2.5 KiB
Lua
-- test_live_remove_foreign.lua
|
|
--
|
|
-- Removing a package through a LIVE context must only remove glacier's
|
|
-- own links (CLAUDE.md bug 26). gl_unlink_pkg used to unlink() the link
|
|
-- destination of every regular file in the package without checking
|
|
-- is_glacier_symlink, so a file the package was REFUSED to overwrite (a
|
|
-- foreign file already at its destination) was deleted on removal, and
|
|
-- the package's symlinks were left dangling.
|
|
|
|
local glacier = require("glacier_ffi")
|
|
local h = require("test_helpers")
|
|
|
|
h.reset_glacier_root()
|
|
io.write("== test_live_remove_foreign ==\n")
|
|
h.sh("rm -rf /glacier/sys")
|
|
h.check(tonumber(glacier.lib.gl_init_sys(false)) == 0, "gl_init_sys")
|
|
|
|
-- A foreign file where the package wants to link, plus a package symlink
|
|
-- (store entry) so the symlink half of removal is covered too.
|
|
h.sh("mkdir -p /usr/share/livefgn && echo foreign > /usr/share/livefgn/data")
|
|
local pkg = h.build_fixture_pkg{ name = "livefgn", ver = "1.0.0", repo = "base" }
|
|
local work = os.tmpname()
|
|
h.sh("rm -f " .. work .. " && mkdir -p " .. work)
|
|
h.sh("cd " .. work .. " && tar xzf " .. h.quote(pkg))
|
|
h.sh("mkdir -p " .. work .. "/livefgn-1.0.0/files/usr/share/livefgn")
|
|
h.sh("echo pkg > " .. work .. "/livefgn-1.0.0/files/usr/share/livefgn/data")
|
|
h.sh("echo own > " .. work .. "/livefgn-1.0.0/files/usr/share/livefgn/own")
|
|
h.sh("ln -s own " .. work .. "/livefgn-1.0.0/files/usr/share/livefgn/own-link")
|
|
h.sh("cd " .. work .. " && tar czf " .. h.quote(pkg) .. " livefgn-1.0.0")
|
|
|
|
local live = glacier.new_context()
|
|
glacier.lib.gl_init_live_context(live, glacier.SCOPE_SYS, 0)
|
|
local st = glacier.lib.gl_install_pkg(live, pkg)
|
|
h.check(tonumber(st) == 0, "live install: " .. glacier.install_name(st))
|
|
h.check(h.exists("/usr/share/livefgn/own"), "the package's own file is linked")
|
|
h.check(h.exists("/usr/share/livefgn/own-link"), "the package's own symlink is linked")
|
|
|
|
local rm = glacier.lib.gl_remove_pkg(live, "livefgn", "base")
|
|
h.check(tonumber(rm) == 0, "live remove: " .. glacier.remove_name(rm))
|
|
|
|
local f = io.open("/usr/share/livefgn/data", "r")
|
|
local content = f and f:read("*l")
|
|
if f then f:close() end
|
|
h.check(content == "foreign", "the foreign file the package never replaced is still there")
|
|
local function lexists(p)
|
|
local ok = os.execute("test -e " .. h.quote(p) .. " -o -L " .. h.quote(p))
|
|
return ok == true or ok == 0
|
|
end
|
|
h.check(not lexists("/usr/share/livefgn/own"), "the package's link is gone")
|
|
h.check(not lexists("/usr/share/livefgn/own-link"), "the package's symlink's link is gone")
|
|
|
|
h.sh("rm -rf /usr/share/livefgn")
|
|
h.summary()
|