M scripts/lua/entry.lua => scripts/lua/entry.lua +0 -3
@@ 1,7 1,4 @@
-package.path = package.path .. ";share/?.lua"
-
local helpers = require('helpers')
-
local paths = require('paths')
local rec = require('recovery')
local backup = require('backup')
M scripts/lua/products/BellHybrid/update_product.lua => scripts/lua/products/BellHybrid/update_product.lua +1 -1
@@ 10,7 10,7 @@ function update_product.execute()
local new_music_dir = recovery.sys.user() .. "/media/app/relaxation"
assert(helpers.mkdirp(new_music_dir))
- helpers.copy_dir(old_music_dir, new_music_dir)
+ helpers.move_dir(old_music_dir, new_music_dir)
helpers.rmdir(old_music_dir)
end
M scripts/lua/products/PurePhone/update_product.lua => scripts/lua/products/PurePhone/update_product.lua +4 -2
@@ 12,9 12,11 @@ function update_product.execute()
local new_battery_config = paths.target.var_dir .. "/batteryFuelGaugeConfig.cfg"
assert(helpers.mkdirp(new_music_dir))
- helpers.copy_dir(old_music_dir, new_music_dir)
+ helpers.move_dir(old_music_dir, new_music_dir)
helpers.rmdir(old_music_dir)
- helpers.copy_file(old_battery_config, new_battery_config)
+ if helpers.exists(old_battery_config) then
+ helpers.copy_file(old_battery_config, new_battery_config)
+ end
end
return update_product
M scripts/lua/share/helpers.lua => scripts/lua/share/helpers.lua +16 -0
@@ 68,6 68,7 @@ function helpers.copy_file(filename_in, filename_out)
local size_in = lfs.attributes(filename_in, "size")
local fd_in = assert(io.open(filename_in, "r"))
local fd_out = assert(io.open(filename_out, "w"))
+ collectgarbage()
while true do
local block = fd_in:read(size)
if not block then
@@ 141,6 142,21 @@ function helpers.copy_dir(from, where)
end
end
+--- Move directory recursively
+-- @function move_dir
+-- @param from source directory
+-- @param where target directory
+function helpers.move_dir(from, where)
+ for filename, attr in dirtree(from) do
+ local name = filename:gsub(from, "")
+ if attr.mode == "directory" then
+ assert(lfs.mkdir(build_path(where, name)))
+ else
+ assert(os.rename(build_path(from, name),build_path(where, name)))
+ end
+ end
+end
+
--- Copy directory recursively using regex filter
-- @function copy_dir_filtered
-- @param from source directory
M scripts/lua/share/ltar.lua => scripts/lua/share/ltar.lua +2 -0
@@ 60,6 60,7 @@ end
local function write_tarfile_chunks(handle, fd)
local size = 1024 * 512
+ collectgarbage()
while true do
local block = fd:read(size)
if not block then
@@ 73,6 74,7 @@ local function read_tarfile_chunks(handle, fd, total_size)
local block_size = 1024 * 512
local to_read = {};
+ collectgarbage()
while total_size > 0 do
if total_size > block_size then
to_read = block_size
M scripts/lua/test/test.lua => scripts/lua/test/test.lua +14 -0
@@ 44,6 44,16 @@ end
function bootctrl.mark_as_bootable(slot)
end
+function bootctrl.mark_as_unbootable(slot)
+end
+
+function bootctrl.mark_as_successful()
+end
+
+function bootctrl.get_current_slot()
+ return bootctrl.slot.b
+end
+
function bootctrl.get_next_active()
end
@@ 59,6 69,10 @@ end
function gui.display_raw_img(width, height, data)
end
+-- Overwrite lfs.chdir method as we do not want to change working directory during running tests on the host
+lfs.chdir = function(dir)
+end
+
sys.user = stub()
sys.source_slot = stub()
sys.target_slot = stub()
M scripts/lua/update.lua => scripts/lua/update.lua +15 -1
@@ 1,4 1,5 @@
local update = {}
+local lfs = require('lfs')
local json = require('lunajson')
local paths = require('paths')
local consts = require('consts')
@@ 76,16 77,29 @@ local function copy_var_directory()
end
+local function enter()
+ -- Mark the current slot as successful
+ recovery.bootctrl.mark_as_successful()
+ -- Mark the target slot as unbootable
+ recovery.bootctrl.mark_as_unbootable(recovery.bootctrl.get_next_active())
+end
+
local function exit()
- print("Finishing update process")
+ print("Finishing update process...")
+
helpers.rmdir(paths.update_dir)
os.remove(paths.update_file)
+
+ -- Update the working directory to the newly updated scripts directory
+ lfs.chdir(recovery.sys.target_slot() .. "/scripts")
+
recovery.bootctrl.mark_as_bootable(recovery.bootctrl.get_next_active())
recovery.bootctrl.mark_as_active(recovery.bootctrl.get_next_active())
recovery.sys.set_os_boot_status(false)
end
function update.execute()
+ enter()
purge_target_slot()
copy_update_package()
copy_databases()
M scripts/lua/update_udm.lua => scripts/lua/update_udm.lua +26 -7
@@ 34,19 34,19 @@ end
local function copy_update_package()
local target_dir = recovery.sys.target_slot()
- print(string.format("Copying content of the update package '%s to '%s'", paths.update_dir, target_dir))
+ print(string.format("Copying content of the update package '%s' to '%s'", paths.update_dir, target_dir))
helpers.copy_dir(paths.update_dir, target_dir)
end
local function copy_databases()
- local from = paths.db_dir
+ local from = recovery.sys.user()
local to = paths.target.db_dir
print(string.format("Copying databases from '%s' to '%s'", from, to))
helpers.copy_dir_filtered(from, to, match_db_files)
end
local function create_directories()
- print("Creating 'log', 'crash_dumps' and 'var' directories")
+ print("Creating 'log', 'crash_dumps' and 'sys' directories")
local target_dir = recovery.sys.target_slot()
lfs.mkdir(target_dir .. "/log")
@@ 66,22 66,41 @@ local function migrate_db()
assert(result == migration.retcode.OK, string.format("Database migration process failed with %d", result))
end
+local function enter()
+ -- Mark the current slot as successful
+ recovery.bootctrl.mark_as_successful()
+ -- Mark the target slot as unbootable
+ recovery.bootctrl.mark_as_unbootable(recovery.bootctrl.get_next_active())
+end
+
local function exit()
print("Finishing update process")
helpers.rmdir(paths.update_dir)
os.remove(paths.update_file)
+
+ -- Update the working directory to the newly updated scripts directory
+ lfs.chdir(recovery.sys.target_slot() .. "/scripts")
+
+ -- Mark the old 'MUDITAOS' partition as unbootable&unsuccessful
+ recovery.bootctrl.mark_as_unbootable(recovery.bootctrl.get_current_slot())
+ -- Mark the 'system_b' as bootable and active
recovery.bootctrl.mark_as_bootable(recovery.bootctrl.get_next_active())
recovery.bootctrl.mark_as_active(recovery.bootctrl.get_next_active())
recovery.sys.set_os_boot_status(false)
end
local function repartition_filesystem()
- print("Repartinioning 'MUDITAOS' and 'BACKUP' partitions and changing theirs labels")
+ print("Repartitioning 'MUDITAOS' and 'BACKUP' partitions and changing theirs labels")
+
+ -- Repartitioning filesystem remounts all available disks. During this process, working directory
+ -- will be set to the default one hence we need to recreate it.
+ local wdir = lfs.currentdir()
recovery.sys.repartition_fs()
+ lfs.chdir(wdir)
end
local function user_remove_directories()
- print("->Removing backup, crash_dums, data, db, logs, tmp directories")
+ print("->Removing backup, crash_dumps, data, db, logs, tmp directories")
if helpers.exists(recovery.sys.user() .. "/backup") then
helpers.rmdir(recovery.sys.user() .. "/backup")
end
@@ 108,9 127,8 @@ local function user_remove_files()
end
local function user_create_directories()
- print("->Creating media, temp directories")
+ print("->Creating media directory")
lfs.mkdir(recovery.sys.user() .. "/media")
- lfs.mkdir(recovery.sys.user() .. "/temp")
end
local function user_product_specific()
@@ 127,6 145,7 @@ local function adjust_user_partition_layout()
end
function update.execute()
+ enter()
repartition_filesystem()
purge_target_slot()
copy_update_package()