Commit a9408908 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

pkg: Function to dump the whole status file

parent 0b24a2fb
......@@ -299,6 +299,26 @@ function status_parse()
return result
end
function status_dump(status)
DBG("Writing status file ", status_file)
--[[
Use a temporary file, so we don't garble the real and precious file.
Write the thing first and then switch attomicaly.
]]
local tmp_file = status_file .. ".tmp"
local f, err = io.open(tmp_file, "w")
if f then
for _, pkg in pairs(status) do
f:write(pkg_status_dump(pkg), "\n")
end
f:close()
-- Override the resulting file
local _, err = os.rename(tmp_file, status_file)
else
error("Couldn't write status file " .. tmp_file .. ": " .. err)
end
end
--[[
Take the .ipk package (passed as the data, not as a path to a file) and unpack it
into a temporary location somewhere under tmp_dir. If you omit tmp_dir, /tmp is used.
......
......@@ -533,6 +533,33 @@ Installed-Time: 1
}))
end
function test_status_dump()
-- Read the status
local status = B.status_parse()
-- Make a copy of the status file, we'are going to write into it
local test_dir = mkdtemp()
table.insert(tmp_dirs, test_dir)
B.status_file = test_dir .. "/status"
B.status_dump(status)
-- Now read it again. It must be the same
local status2 = B.status_parse()
assert_table_equal(status, status2)
-- Change something in the status. Add a new package
status["New"] = {
Package = "New",
Version = "1",
["Installed-Time"] = "1",
Depends = { "Dep1", "dep2" },
Status = { flag = true }
}
-- Do one more store-read-compare cycle
B.status_dump(status)
local status3 = B.status_parse()
-- The status_parse always generates list of files, even if there are none
status["New"].files = {}
assert_table_equal(status, status3)
end
function setup()
local sdir = os.getenv("S") or "."
-- Use a shortened version of a real status file for tests
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment