mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 10:21:45 -04:00
cp and mv programs will now accept a directory as the target location and append the original file name automatically in that case
This commit is contained in:
parent
d395db6d7c
commit
f93fc78a94
@ -1,11 +1,18 @@
|
|||||||
local args = shell.parse(...)
|
local args, options = shell.parse(...)
|
||||||
if #args < 2 then
|
if #args < 2 then
|
||||||
print("Usage: cp <from> <to>")
|
print("Usage: cp [-f] <from> <to>")
|
||||||
|
print(" -f: overwrite file if it already exists.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local from, reason = shell.resolve(args[1])
|
local from = shell.resolve(args[1])
|
||||||
local to, reason = shell.resolve(args[2])
|
local to = shell.resolve(args[2])
|
||||||
|
if fs.isDirectory(to) then
|
||||||
|
to = to .. "/" .. fs.name(from)
|
||||||
|
end
|
||||||
|
if fs.exists(to) and not options.f then
|
||||||
|
error("target file exists")
|
||||||
|
end
|
||||||
local result, reason = fs.copy(from, to)
|
local result, reason = fs.copy(from, to)
|
||||||
if not result then
|
if not result then
|
||||||
print(reason)
|
print(reason)
|
||||||
|
@ -1,12 +1,22 @@
|
|||||||
local args = shell.parse(...)
|
local args, options = shell.parse(...)
|
||||||
if #args < 2 then
|
if #args < 2 then
|
||||||
print("Usage: mv <from> <to>")
|
print("Usage: mv [-f] <from> <to>")
|
||||||
|
print(" -f: overwrite file if it already exists.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local from = shell.resolve(args[1])
|
local from = shell.resolve(args[1])
|
||||||
local to = shell.resolve(args[2])
|
local to = shell.resolve(args[2])
|
||||||
|
if fs.isDirectory(to) then
|
||||||
|
to = to .. "/" .. fs.name(from)
|
||||||
|
end
|
||||||
|
if fs.exists(to) then
|
||||||
|
if not options.f then
|
||||||
|
error("target file exists")
|
||||||
|
end
|
||||||
|
fs.remove(to)
|
||||||
|
end
|
||||||
local result, reason = os.rename(from, to)
|
local result, reason = os.rename(from, to)
|
||||||
if not result then
|
if not result then
|
||||||
print(reason)
|
print(reason or "unknown error")
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package li.cil.oc.server.fs
|
package li.cil.oc.server.fs
|
||||||
|
|
||||||
import java.io
|
import java.io
|
||||||
|
import java.io.FileNotFoundException
|
||||||
import li.cil.oc.api.fs.Mode
|
import li.cil.oc.api.fs.Mode
|
||||||
import net.minecraft.nbt.{NBTTagList, NBTTagCompound}
|
import net.minecraft.nbt.{NBTTagList, NBTTagCompound}
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
@ -62,7 +63,8 @@ trait VirtualFileSystem extends OutputStreamFileSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override def rename(from: String, to: String) =
|
override def rename(from: String, to: String) =
|
||||||
if (from != "" && exists(from) && !exists(to)) {
|
if (from == "" || !exists(from)) throw new FileNotFoundException()
|
||||||
|
else if (!exists(to)) {
|
||||||
val segmentsTo = segments(to)
|
val segmentsTo = segments(to)
|
||||||
root.get(segmentsTo.dropRight(1)) match {
|
root.get(segmentsTo.dropRight(1)) match {
|
||||||
case Some(toParent: VirtualDirectory) =>
|
case Some(toParent: VirtualDirectory) =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user