Better change-detection in boot file.
This commit is contained in:
parent
49b5236521
commit
2885d1a183
1 changed files with 35 additions and 17 deletions
|
@ -21,29 +21,20 @@ if HOMECONNECTION:isconnected {
|
|||
print "============= BOOT SEQUENCE COMPLETE =============".
|
||||
|
||||
|
||||
function copy_scripts {
|
||||
local function copy_scripts {
|
||||
//
|
||||
// Copy all .ks-files from the archive to the CPU's internal storage.
|
||||
//
|
||||
parameter archive_dir is ARCHIVE:files.
|
||||
|
||||
for item in archive_dir:values {
|
||||
function iteration { // allows for quick-bailing using 'return' (kOS doesn't have the 'continue' keyword
|
||||
local item_path is "/" + path(item):segments:join("/"). // full path of item without volume id
|
||||
if item:name[0] = "." // skip Linux hidden files and directories (e.g. .git)
|
||||
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.
|
||||
copypath(item, path(CORE:volume):combine(item_path)).
|
||||
if item_path = CORE:bootfilename {
|
||||
|
@ -52,6 +43,33 @@ function copy_scripts {
|
|||
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.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue