change orgs to use id numbers as their table key and function input param
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
modpol.datadir = modpol.topdir .. "/data"
|
||||
modpol.file_ledger = modpol.datadir .. "/ledger.dat"
|
||||
modpol.file_orgs = modpol.datadir .. "/orgs.dat"
|
||||
modpol.file_old_ledgers = modpol.datadir .. "/old_ledgers.dat"
|
||||
|
||||
os.execute ("mkdir -p " .. modpol.datadir)
|
||||
|
||||
@@ -43,8 +44,7 @@ end
|
||||
|
||||
local store_orgs = function()
|
||||
local ok = modpol.ocutil.file_write (modpol.file_orgs,
|
||||
modpol.serpent.dump (modpol.orgs))
|
||||
|
||||
modpol.serpent.dump (modpol.orgs))
|
||||
if ok ~= true then
|
||||
modpol.ocutil.fatal_error ("store_data: orgs")
|
||||
end
|
||||
@@ -55,12 +55,32 @@ modpol.serpent.dump (modpol.orgs))
|
||||
modpol.ocutil.log (nn .. " orgs stored to disk")
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- This function stores "old_ledgers" data to disk.
|
||||
|
||||
local store_old_ledgers = function()
|
||||
|
||||
local ok = modpol.ocutil.file_write (modpol.file_old_ledgers,
|
||||
modpol.serpent.dump (modpol.old_ledgers))
|
||||
|
||||
|
||||
if ok ~= true then
|
||||
modpol.ocutil.fatal_error ("store_data: orgs")
|
||||
end
|
||||
|
||||
local nn = modpol.ocutil.table_length (modpol.old_ledgers)
|
||||
local str = "entries"
|
||||
if nn == 1 then str = "entry" end
|
||||
modpol.ocutil.log (nn .. " orgs stored to disk")
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- This function stores data to disk.
|
||||
|
||||
modpol.store_data = function()
|
||||
store_ledger()
|
||||
store_orgs()
|
||||
store_old_ledgers()
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
@@ -105,12 +125,34 @@ local load_orgs = function()
|
||||
end
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- This function loads "old_ledgers" data from disk.
|
||||
|
||||
local load_old_ledgers = function()
|
||||
local obj = modpol.ocutil.file_read (modpol.file_old_ledgers )
|
||||
if obj ~= nil then
|
||||
local func, err = load (obj)
|
||||
if err then
|
||||
modpol.ocutil.fatal_error ("load_data: orgs" )
|
||||
end
|
||||
modpol.orgs = func()
|
||||
|
||||
local nn = modpol.ocutil.table_length (modpol.file_old_ledgers)
|
||||
local str = "entries"
|
||||
if nn == 1 then str = "entry" end
|
||||
modpol.ocutil.log (nn .. " orgs loaded from disk")
|
||||
else
|
||||
modpol.ocutil.log ("No stored old ledgers data found")
|
||||
end
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- This function loads stored data from disk.
|
||||
|
||||
modpol.load_storage = function()
|
||||
load_ledger()
|
||||
load_orgs()
|
||||
load_old_ledgers()
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
|
||||
Reference in New Issue
Block a user