mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComputers into master-MC1.8.9
This commit is contained in:
commit
67d595196c
@ -93,7 +93,7 @@ local function recurse(fromPath, toPath, origin)
|
||||
if options.x and origin and mounts[fs.canonical(fromPath)] then
|
||||
return true
|
||||
end
|
||||
if fs.get(fromPath) == fs.get(toPath) and fs.canonical(toPath):find(fs.canonical(fromPath),1,true) then
|
||||
if fs.get(fromPath) == fs.get(toPath) and (fs.canonical(toPath).."/"):find(fs.canonical(fromPath).."/",1,true) then
|
||||
return nil, "cannot copy a directory, `" .. fromPath .. "', into itself, `" .. toPath .. "'"
|
||||
end
|
||||
if not fs.exists(toPath) then
|
||||
|
@ -67,7 +67,8 @@ end
|
||||
|
||||
for _, row in ipairs(result) do
|
||||
for col, value in ipairs(row) do
|
||||
io.write(text.padRight(value, m[col] + 2))
|
||||
local padding = col == #row and 0 or 2
|
||||
io.write(text.padRight(value, m[col] + padding))
|
||||
end
|
||||
print()
|
||||
end
|
||||
|
@ -133,7 +133,7 @@ if #args == 0 or options.i then
|
||||
term.write(tostring(env._PROMPT or "lua> "))
|
||||
gpu.setForeground(foreground)
|
||||
local command = term.read(history, nil, hint)
|
||||
if command == nil or command == "" then -- eof
|
||||
if not command then -- eof
|
||||
return
|
||||
end
|
||||
local code, reason
|
||||
|
@ -10,30 +10,31 @@ if #args < 2 then
|
||||
end
|
||||
|
||||
local function is_mount(path)
|
||||
if not fs.isDirectory(path) then return false end
|
||||
path = fs.canonical(path) .. '/'
|
||||
end
|
||||
|
||||
local from = args[1] ~= "" and shell.resolve(args[1])
|
||||
local to = args[2] ~= "" and shell.resolve(args[2])
|
||||
|
||||
if not from or not fs.exists(from) then
|
||||
io.stderr:write(string.format("No such file or directory: '%s'\n", args[1]))
|
||||
return 1
|
||||
elseif not to then
|
||||
io.stderr:write(string.format("Cannot move '%s' to '%s' No such file or directory\n", args[1], args[2]))
|
||||
return 1
|
||||
elseif fs.get(from).isReadOnly() then
|
||||
io.stderr:write("cannot remove " .. args[1] .. ", filesystem is readonly\n");
|
||||
return 1
|
||||
elseif fs.get(to).isReadOnly() then
|
||||
io.stderr:write("cannot write to " .. args[2] .. ", filesystem is readonly\n");
|
||||
return 1
|
||||
elseif fs.isDirectory(from) then
|
||||
local path = fs.canonical(from) .. '/'
|
||||
for driver, mount_point in fs.mounts() do
|
||||
if path == mount_point then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function is_readonly(path)
|
||||
return fs.get(path).isReadOnly()
|
||||
end
|
||||
|
||||
local from = shell.resolve(args[1])
|
||||
local to = shell.resolve(args[2])
|
||||
|
||||
if is_readonly(to) then
|
||||
io.stderr:write("cannot write to " .. to .. ", filesystem is readonly\n");
|
||||
io.stderr:write("cannot move " .. args[1] .. ", it is a mount point\n");
|
||||
return 1
|
||||
end
|
||||
|
||||
if is_mount(from) then
|
||||
io.stderr:write("cannot move " .. from .. ", it is a mount point\n");
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
if fs.isDirectory(to) then
|
||||
@ -44,16 +45,15 @@ if fs.exists(to) then
|
||||
io.stderr:write("target file exists\n")
|
||||
return 1
|
||||
end
|
||||
fs.remove(to)
|
||||
end
|
||||
|
||||
local result, reason
|
||||
if fs.get(from) == fs.get(to) then -- same filesystem
|
||||
result, reason = os.rename(from, to)
|
||||
else
|
||||
result, reason = sh.execute(nil, shell.resolve("cp","lua"), "-r", from, to)
|
||||
result, reason = sh.execute(nil, shell.resolve("cp","lua"), "-rf", from, to)
|
||||
if result then
|
||||
result, reason = sh.execute(nil, shell.resolve("rm","lua"), "-r", from)
|
||||
result, reason = sh.execute(nil, shell.resolve("rm","lua"), "-rf", from)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -24,6 +24,21 @@ local bVerbose = options.v or options.verbose
|
||||
local bEmptyDirs = options.d or options.dir
|
||||
local promptLevel = (options.I and 3) or (options.i and 1) or 0
|
||||
|
||||
bVerbose = bVerbose and not bForce
|
||||
promptLevel = bForce and 0 or promptLevel
|
||||
|
||||
local function perr(...)
|
||||
if not bForce then
|
||||
io.stderr:write(...)
|
||||
end
|
||||
end
|
||||
|
||||
local function pout(...)
|
||||
if not bForce then
|
||||
io.stdout:write(...)
|
||||
end
|
||||
end
|
||||
|
||||
local metas = {}
|
||||
|
||||
-- promptLevel 3 done before fs.exists
|
||||
@ -50,6 +65,9 @@ local function unlink(path)
|
||||
end
|
||||
|
||||
local function confirm()
|
||||
if bForce then
|
||||
return true
|
||||
end
|
||||
local r = io.read("*l")
|
||||
return r == 'y' or r == 'yes'
|
||||
end
|
||||
@ -61,7 +79,7 @@ local function remove_all(parent)
|
||||
|
||||
local all_ok = true
|
||||
if bRec and promptLevel == 1 then
|
||||
io.stdout:write(string.format("rm: descend into directory `%s'? ", parent.rel))
|
||||
pout(string.format("rm: descend into directory `%s'? ", parent.rel))
|
||||
if not confirm() then
|
||||
return false
|
||||
end
|
||||
@ -81,16 +99,13 @@ local function remove(meta)
|
||||
end
|
||||
|
||||
if not _exists(meta) then
|
||||
io.stderr:write(
|
||||
string.format("rm: cannot remove `%s': No such file or directory\n", meta.rel))
|
||||
perr(string.format("rm: cannot remove `%s': No such file or directory\n", meta.rel))
|
||||
return false
|
||||
elseif _dir(meta) and not bRec and not (_empty(meta) and bEmptyDirs) then
|
||||
if not bEmptyDirs then
|
||||
io.stderr:write(
|
||||
string.format("rm: cannot remove `%s': Is a directory\n", meta.rel))
|
||||
perr(string.format("rm: cannot remove `%s': Is a directory\n", meta.rel))
|
||||
else
|
||||
io.stderr:write(
|
||||
string.format("rm: cannot remove `%s': Directory not empty\n", meta.rel))
|
||||
perr(string.format("rm: cannot remove `%s': Directory not empty\n", meta.rel))
|
||||
end
|
||||
return false
|
||||
end
|
||||
@ -98,11 +113,11 @@ local function remove(meta)
|
||||
local ok = true
|
||||
if promptLevel == 1 then
|
||||
if _dir(meta) then
|
||||
io.stdout:write(string.format("rm: remove directory `%s'? ", meta.rel))
|
||||
pout(string.format("rm: remove directory `%s'? ", meta.rel))
|
||||
elseif meta.link then
|
||||
io.stdout:write(string.format("rm: remove symbolic link `%s'? ", meta.rel))
|
||||
pout(string.format("rm: remove symbolic link `%s'? ", meta.rel))
|
||||
else -- file
|
||||
io.stdout:write(string.format("rm: remove regular file `%s'? ", meta.rel))
|
||||
pout(string.format("rm: remove regular file `%s'? ", meta.rel))
|
||||
end
|
||||
|
||||
ok = confirm()
|
||||
@ -110,14 +125,13 @@ local function remove(meta)
|
||||
|
||||
if ok then
|
||||
if _readonly(meta) then
|
||||
io.stderr:write(
|
||||
string.format("rm: cannot remove `%s': Is read only\n", meta.rel))
|
||||
perr(string.format("rm: cannot remove `%s': Is read only\n", meta.rel))
|
||||
return false
|
||||
elseif not unlink(_path(meta)) then
|
||||
io.stderr:write(meta.rel .. ": failed to be removed\n")
|
||||
perr(meta.rel .. ": failed to be removed\n")
|
||||
ok = false
|
||||
elseif bVerbose then
|
||||
io.write("removed '" .. meta.rel .. "'\n");
|
||||
pout("removed '" .. meta.rel .. "'\n");
|
||||
end
|
||||
end
|
||||
|
||||
@ -129,7 +143,7 @@ for _,arg in ipairs(args) do
|
||||
end
|
||||
|
||||
if promptLevel == 3 and #metas > 3 then
|
||||
io.stdout:write(string.format("rm: remove %i arguments? ", #metas))
|
||||
pout(string.format("rm: remove %i arguments? ", #metas))
|
||||
if not confirm() then
|
||||
return
|
||||
end
|
||||
@ -140,3 +154,5 @@ for _,meta in ipairs(metas) do
|
||||
local result = remove(meta)
|
||||
ok = ok and result
|
||||
end
|
||||
|
||||
return bForce or ok
|
||||
|
@ -57,9 +57,3 @@ event.listen("component_added", components_changed)
|
||||
event.listen("component_available", components_changed)
|
||||
event.listen("component_unavailable", components_changed)
|
||||
|
||||
event.listen("screen_resized", function(_,addr,w,h)
|
||||
local window = term.internal.window()
|
||||
if term.isAvailable(window) and term.screen(window) == addr and window.fullscreen then
|
||||
window.w,window.h = w,h
|
||||
end
|
||||
end)
|
||||
|
@ -157,10 +157,10 @@ do
|
||||
computer.pushSignal("component_added", c, t)
|
||||
end
|
||||
os.sleep(0.5) -- Allow signal processing by libraries.
|
||||
computer.pushSignal("init") -- so libs know components are initialized.
|
||||
|
||||
status("Initializing system...")
|
||||
os.sleep(0.1) -- Allow init processing.
|
||||
|
||||
computer.pushSignal("init") -- so libs know components are initialized.
|
||||
require("event").pull(1, "init") -- Allow init processing.
|
||||
runlevel = 1
|
||||
end
|
||||
|
||||
|
@ -252,27 +252,32 @@ function sh.internal.createThreads(commands, eargs, env)
|
||||
|
||||
threads[i] = thread
|
||||
|
||||
if thread then
|
||||
-- smart check if ios should be loaded
|
||||
if tx.first(args, function(token) return token == "<" or token:find(">") end) then
|
||||
args, reason = sh.internal.buildCommandRedirects(thread, args)
|
||||
end
|
||||
end
|
||||
|
||||
if not args or not thread then
|
||||
if not thread then
|
||||
for i,t in ipairs(threads) do
|
||||
process.internal.close(t)
|
||||
end
|
||||
return nil, reason
|
||||
end
|
||||
|
||||
process.info(thread).data.args = tx.concat(args, eargs or {})
|
||||
process.info(thread).data.args = args
|
||||
end
|
||||
|
||||
if #threads > 1 then
|
||||
sh.internal.buildPipeChain(threads)
|
||||
end
|
||||
|
||||
for i = 1, #threads do
|
||||
local thread = threads[i]
|
||||
local args = process.info(thread).data.args
|
||||
|
||||
-- smart check if ios should be loaded
|
||||
if tx.first(args, function(token) return token == "<" or token:find(">") end) then
|
||||
args, reason = sh.internal.buildCommandRedirects(thread, args)
|
||||
end
|
||||
|
||||
process.info(thread).data.args = tx.concat(args, eargs or {})
|
||||
end
|
||||
|
||||
return threads
|
||||
end
|
||||
|
||||
|
@ -19,6 +19,11 @@ local local_env = {unicode=unicode,event=event,process=process,W=W,kb=kb}
|
||||
function term.internal.open(...)
|
||||
local dx, dy, w, h = ...
|
||||
local window = {x=1,y=1,fullscreen=select("#",...)==0,dx=dx or 0,dy=dy or 0,w=w,h=h,blink=true}
|
||||
event.listen("screen_resized", function(_,addr,w,h)
|
||||
if term.isAvailable(window) and term.screen(window) == addr and window.fullscreen then
|
||||
window.w,window.h = w,h
|
||||
end
|
||||
end)
|
||||
return window
|
||||
end
|
||||
|
||||
@ -239,7 +244,9 @@ function term.readKeyboard(ops)
|
||||
|
||||
while true do
|
||||
local name, address, char, code = term.internal.pull(input)
|
||||
assert(term.isAvailable(), "term_unavailable")
|
||||
if not term.isAvailable() then
|
||||
return
|
||||
end
|
||||
|
||||
-- we have to keep checking what kb is active in case it is switching during use
|
||||
-- we could have multiple screens, each with keyboards active
|
||||
|
@ -9,7 +9,7 @@ local local_env = {tx=tx,unicode=unicode}
|
||||
|
||||
text.internal = {}
|
||||
|
||||
text.syntax = {"^%d*>>?&%d+$",";","&&","||?","^%d*>>?",">>?","<"}
|
||||
text.syntax = {"^%d?>>?&%d+$",";","&&","||?","^%d?>>?",">>?","<"}
|
||||
|
||||
function --[[@delayloaded-start@]] text.detab(value, tabWidth)
|
||||
checkArg(1, value, "string")
|
||||
|
Loading…
x
Reference in New Issue
Block a user