glacier-ng 4.0.0
This commit is contained in:
commit
0cf4829fa5
159 files changed
+33717
No files matched your search
@@ -0,0 +1,68 @@
|
||||
-- test_index_abort.lua
|
||||
--
|
||||
-- An aborted transaction must leave the live index exactly as it was
|
||||
-- (CLAUDE.md bug 25). Index files are named to the second, and stage
|
||||
-- seeding HARDLINKS live's into the stage, so a staged install in the
|
||||
-- same second as the last commit produces an index file with the same
|
||||
-- name as live's, sharing its inode. gl_rebuild_index used to
|
||||
-- fopen(name, "w") it, rewriting the live index in place.
|
||||
--
|
||||
-- The collision depends on timing, so this repeats commit + staged
|
||||
-- install until the stage's new index really does share a name with
|
||||
-- live's, then checks live after the abort. Without a collision there's
|
||||
-- nothing to test, and that is reported as a failure rather than a pass.
|
||||
|
||||
local glacier = require("glacier_ffi")
|
||||
local h = require("test_helpers")
|
||||
|
||||
h.reset_glacier_root()
|
||||
|
||||
local uid = 1004
|
||||
io.write("== test_index_abort (uid " .. uid .. ") ==\n")
|
||||
glacier.lib.gl_init_user(uid, false)
|
||||
|
||||
local function read(path)
|
||||
local f = io.open(path, "r")
|
||||
if not f then return nil end
|
||||
local s = f:read("*a")
|
||||
f:close()
|
||||
return s
|
||||
end
|
||||
|
||||
local index_dir = "/glacier/usr/" .. uid .. "/index"
|
||||
local stage_index = "/glacier/usr/" .. uid .. "/stage/index"
|
||||
|
||||
local collided = false
|
||||
for i = 1, 20 do
|
||||
-- A commit, so live gets a fresh index file named for this second.
|
||||
local path = h.build_fixture_pkg{ name = "base" .. i, ver = "1.0.0", repo = "core" }
|
||||
local c = glacier.new_context()
|
||||
assert(tonumber(glacier.lib.gl_init_stage_context(c, glacier.SCOPE_USR, uid)) == 0)
|
||||
assert(tonumber(glacier.lib.gl_install_pkg(c, path)) == 0)
|
||||
assert(tonumber(glacier.lib.gl_commit_transaction(c)) == 0)
|
||||
|
||||
local p = io.popen("readlink " .. h.quote(index_dir .. "/current"))
|
||||
local live_name = p:read("*l"); p:close()
|
||||
local before = read(index_dir .. "/" .. live_name)
|
||||
|
||||
-- Straight away: a staged install, then abort.
|
||||
local extra = h.build_fixture_pkg{ name = "aborted" .. i, ver = "1.0.0", repo = "core" }
|
||||
local s = glacier.new_context()
|
||||
assert(tonumber(glacier.lib.gl_init_stage_context(s, glacier.SCOPE_USR, uid)) == 0)
|
||||
assert(tonumber(glacier.lib.gl_install_pkg(s, extra)) == 0)
|
||||
p = io.popen("readlink " .. h.quote(stage_index .. "/current"))
|
||||
local stage_name = p:read("*l"); p:close()
|
||||
glacier.lib.gl_abort_transaction(s)
|
||||
|
||||
if stage_name == live_name then
|
||||
collided = true
|
||||
h.check(read(index_dir .. "/" .. live_name) == before,
|
||||
"live index unchanged after an aborted same-second transaction (attempt " .. i .. ")")
|
||||
h.check(not (read(index_dir .. "/current") or ""):find("aborted" .. i, 1, true),
|
||||
"live index doesn't list the aborted package")
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
h.check(collided, "a same-second index name collision happened (needed for this test)")
|
||||
h.summary()
|
||||
Reference in new issue
Block a user