Better change-detection in boot file.

This commit is contained in:
Casper V. Kristensen 2019-02-16 22:37:59 +01:00
parent 49b5236521
commit 2885d1a183
Signed by: caspervk
GPG key ID: 289CA03790535054

View file

@ -21,29 +21,20 @@ if HOMECONNECTION:isconnected {
print "============= BOOT SEQUENCE COMPLETE =============". print "============= BOOT SEQUENCE COMPLETE =============".
function copy_scripts { local function copy_scripts {
// //
// Copy all .ks-files from the archive to the CPU's internal storage. // Copy all .ks-files from the archive to the CPU's internal storage.
// //
parameter archive_dir is ARCHIVE:files. parameter archive_dir is ARCHIVE:files.
for item in archive_dir:values { for item in archive_dir:values {
function iteration { // allows for quick-bailing using 'return' (kOS doesn't have the 'continue' keyword // Recurse on directories
local item_path is "/" + path(item):segments:join("/"). // full path of item without volume id if not item:isfile {
if item:name[0] = "." // skip Linux hidden files and directories (e.g. .git) copy_scripts(item:list).
return. }
// Recurse on directories
if not item:isfile {
copy_scripts(item:list).
return.
}
if item:extension <> "ks" // skip non-script items (e.g. README.md)
return.
if CORE:volume:exists(item_path) and item:size = CORE:volume:open(item_path):size // skip if file exists locally with the same size
return.
local item_path is "/" + path(item):segments:join("/"). // full path of item without volume id
if should_copy(item, item_path) {
print "Copying " + item_path. print "Copying " + item_path.
copypath(item, path(CORE:volume):combine(item_path)). copypath(item, path(CORE:volume):combine(item_path)).
if item_path = CORE:bootfilename { if item_path = CORE:bootfilename {
@ -52,6 +43,33 @@ function copy_scripts {
reboot. reboot.
} }
} }
iteration().
} }
} }
local function should_copy {
parameter item.
parameter item_path.
// Skip Linux hidden files and directories (e.g. .git)
if item:name[0] = "." {
return false.
}
// Skip non-script items (e.g. README.md)
if item:extension <> "ks" {
return false.
}
// Always copy files we don't have
if not CORE:volume:exists(item_path) {
return true.
}
// Copy file if local one has different size
if item:size <> CORE:volume:open(item_path):size {
return true.
}
// Copy file if local one has different contents
if item:readall:string <> CORE:volume:open(item_path):readall:string {
return true.
}
return false.
}