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 2387ab37b..82be2fc9c 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/cp.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/cp.lua @@ -67,9 +67,10 @@ local function recurse(fromPath, toPath, origin) local isLink, target = fs.isLink(fromPath) local toIsLink, toLinkTarget = fs.isLink(toPath) local same_path = fs.canonical(isLink and target or fromPath) == fs.canonical(toIsLink and toLinkTarget or toPath) + local same_link = isLink and toIsLink and same_path local toExists = fs.exists(toPath) - - if isLink and options.P and (not toExists or not same_path) then + + if isLink and options.P and not (toExists and same_path and not toIsLink) then if toExists and options.n then return true end 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 31e48d79d..204e71857 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/install.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/install.lua @@ -23,7 +23,6 @@ if ec ~= nil and ec ~= 0 then end local write = io.write -local read = io.read write("Installation complete!\n") if options.setlabel then @@ -39,8 +38,7 @@ end if options.reboot then write("Reboot now? [Y/n] ") - local result = read() or "n" - if result:sub(1, 1):lower() == "y" then + if ((io.read() or "n").."y"):match("^%s*[Yy]") then write("\nRebooting now!\n") computer.shutdown(true) end diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/ln.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/ln.lua index 029b83d63..85bdc1a52 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/ln.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/ln.lua @@ -9,6 +9,13 @@ if #dirs == 0 then end local target = shell.resolve(dirs[1]) + +-- don't link from target if it doesn't exist, unless it is a broken link +if not fs.exists(target) and not fs.isLink(target) then + io.stderr:write("ln: failed to access '" .. target .. "': No such file or directory\n") + return 1 +end + local linkpath if #dirs > 1 then linkpath = shell.resolve(dirs[2]) diff --git a/src/main/resources/assets/opencomputers/loot/openos/lib/sh.lua b/src/main/resources/assets/opencomputers/loot/openos/lib/sh.lua index 4a3a12803..159e9072d 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/lib/sh.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/lib/sh.lua @@ -666,28 +666,34 @@ function --[[@delayloaded-start@]] sh.internal.hasValidPiping(words, pipes) local semi_split = tx.find(text.syntax, {";"}) -- all symbols before ; in syntax CAN be repeated pipes = pipes or tx.sub(text.syntax, semi_split + 1) - local pies = tx.select(words, function(parts, i) - return #parts == 1 and #text.split(parts[1].txt, pipes, true) == 0 and true or false - end) - - local bad_pipe - local last = 0 - for k,v in ipairs(pies) do - if v then - if k-last == 1 then - bad_pipe = words[k][1].txt - break + local state = "" -- cannot start on a pipe + + for w=1,#words do + local word = words[w] + for p=1,#word do + local part = word[p] + if part.qr then + state = nil + elseif part.txt == "" then + state = nil -- not sure how this is possible (empty part without quotes?) + elseif #text.split(part.txt, pipes, true) == 0 then + local prev = state + state = part.txt + if prev then -- cannot have two pipes in a row + word = nil + break + end + else + state = nil end - last=k + end + if not word then -- bad pipe + break end end - if not bad_pipe and last == #pies then - bad_pipe = words[last][1].txt - end - - if bad_pipe then - return false, "parse error near " .. bad_pipe + if state then + return false, "parse error near " .. state else return true 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 8c0a8cd42..eaa2c8591 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 @@ -7,7 +7,6 @@ local unicode = require("unicode") local text = require("text") local write = io.write -local read = io.read local args, options = shell.parse(...) @@ -174,7 +173,7 @@ 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 - return loadfile("/lib/tools/install_utils.lua", "bt", _G)('install', options) + os.exit(loadfile("/lib/tools/install_utils.lua", "bt", _G)('install', options)) end local cp_args = @@ -190,8 +189,7 @@ if #options.targets > 1 or options.to then special_target = " to " .. cp_args[3] end io.write("Install " .. source_display .. special_target .. "? [Y/n] ") -local choice = read():lower() -if choice ~= "y" and choice ~= "" then +if not ((io.read() or "n").."y"):match("^%s*[Yy]") then write("Installation cancelled\n") os.exit() end 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 68cd2bce5..cbaae9a70 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 @@ -22,8 +22,8 @@ local function select_prompt(devs, prompt) io.write("Enter 'q' to cancel the installation: ") choice = nil while not choice do - result = io.read() - if result:sub(1, 1):lower() == "q" then + result = io.read() or "q" + if result == "q" then os.exit() end local number = tonumber(result)