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
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 =, "w")
if f then
for _, pkg in pairs(status) do
f:write(pkg_status_dump(pkg), "\n")
-- Override the resulting file
local _, err = os.rename(tmp_file, status_file)
error("Couldn't write status file " .. tmp_file .. ": " .. err)
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
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"
-- 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
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)
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