From 203649a2dcd700c0bbb3d307cf88c2f426b93143 Mon Sep 17 00:00:00 2001 From: payonel Date: Sun, 12 Jun 2016 15:41:49 -0700 Subject: [PATCH] install fix and cleanup, cp quality, network loot .prop install was crashing if there were no options. Having no options is a perfectly valid case where install is trying to exit early (e.g. --help, or user cancelled) I forgot the check for nil. During tests I found that cp was unnecessarily slow due to constant event pulling on every file. I introduced a 4 second gap between checking events. But his caused cp very hard (nearly impossible) to interrupt. Thus, it is preferrable to slow down copy so that the user could interrupt it. Also, thanks to Inari, we have improved the text of the install prompts. Please review and comment if you feel the text still needs some revising. I'm not a technical writer, so I hope we are making this simple. Also, if the user tries to run install with the network loot disk, the /data dir will be copied to /, and the user probably wants the data/. dir used. Using .prop's {fromDir="/data/"} fixes this --- .../assets/opencomputers/loot/network/.prop | 1 + .../assets/opencomputers/loot/openos/bin/cp.lua | 8 +------- .../opencomputers/loot/openos/bin/install.lua | 2 ++ .../loot/openos/lib/tools/install_basics.lua | 14 +++++++------- .../loot/openos/lib/tools/install_utils.lua | 12 +++++++++--- 5 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 src/main/resources/assets/opencomputers/loot/network/.prop diff --git a/src/main/resources/assets/opencomputers/loot/network/.prop b/src/main/resources/assets/opencomputers/loot/network/.prop new file mode 100644 index 000000000..cea2062f9 --- /dev/null +++ b/src/main/resources/assets/opencomputers/loot/network/.prop @@ -0,0 +1 @@ +{fromDir="/data/"} diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/cp.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/cp.lua index 6f2ba1d07..2387ab37b 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/cp.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/cp.lua @@ -19,17 +19,11 @@ end local exit_code = nil options.P = options.P or options.r --- interrupting is important, but not EVERY copy -local greedy = computer.uptime() - local function status(from, to) if options.v then io.write(from .. " -> " .. to .. "\n") end - if computer.uptime() - greedy > 4 then - os.sleep(0) -- allow interrupting - greedy = computer.uptime() - end + os.sleep(0) -- allow interrupting end local result, reason diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/install.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/install.lua index 65029f329..d063cc208 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/install.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/install.lua @@ -8,6 +8,8 @@ do options = basic(...) end +if not options then return end + if computer.freeMemory() < 50000 then print("Low memory, collecting garbage") for i=1,20 do os.sleep(0) end diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/tools/install_basics.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/tools/install_basics.lua index 13848399f..8c0a8cd42 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/tools/install_basics.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/tools/install_basics.lua @@ -51,7 +51,7 @@ local function cleanPath(path) if path then local rpath = shell.resolve(path) if fs.isDirectory(rpath) then - return fs.canonical(rpath):gsub("/+$", "") .. '/' + return fs.canonical(rpath) .. '/' end end end @@ -84,8 +84,7 @@ up_deprecate('name', 'label') options.source_root = cleanPath(options.from) options.target_root = cleanPath(options.to) -options.source_dir = (options.fromDir or "") .. '.' -options.target_dir = (options.root or options.toDir or "") +options.target_dir = fs.canonical(options.root or options.toDir or "") options.update = options.u or options.update @@ -167,10 +166,11 @@ if not target then return end options.target_root = options.target_root or target.path -- now that source is selected, we can update options -options.label = options.label or source.prop.label -options.setlabel = source.prop.setlabel and not options.nosetlabel -options.setboot = source.prop.setboot and not options.nosetboot -options.reboot = source.prop.reboot and not options.noreboot +options.label = options.label or source.prop.label +options.setlabel = source.prop.setlabel and not options.nosetlabel +options.setboot = source.prop.setboot and not options.nosetboot +options.reboot = source.prop.reboot and not options.noreboot +options.source_dir = fs.canonical(source.prop.fromDir or options.fromDir or "") .. '/.' local installer_path = options.source_root .. "/.install" if fs.exists(installer_path) then diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/tools/install_utils.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/tools/install_utils.lua index d8db67bc6..68cd2bce5 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/tools/install_utils.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/tools/install_utils.lua @@ -1,11 +1,11 @@ local cmd, options = ... -local function select_prompt(devs, direction) +local function select_prompt(devs, prompt) table.sort(devs, function(a, b) return a.path 1 then - io.write("Select the device to install " .. direction .. '\n') + print(prompt) for i = 1, #devs do local src = devs[i] @@ -59,7 +59,13 @@ if cmd == 'select' then os.exit(1) end - return select_prompt(options.sources, "from"), select_prompt(options.targets, "to") + local source = select_prompt(options.sources, "What do you want to install?") + if #options.sources > 1 and #options.targets > 1 then + print() + end + local target = select_prompt(options.targets, "Where do you want to install to?") + + return source, target elseif cmd == 'install' then local installer_path = options.source_root .. "/.install"