Some minor fixes.

This commit is contained in:
Florian Nücke 2014-10-13 13:19:52 +02:00
parent b2f50b3ac7
commit f0ec5ac0d4
2 changed files with 23 additions and 12 deletions

View File

@ -43,7 +43,12 @@ function process.load(path, env, init, name)
reason = "no exec command"
else
code = function()
return require("shell").execute(command, env, path)
local result = table.pack(require("shell").execute(command, env, path))
if not result[1] then
error(result[2], 0)
else
return table.unpack(result, 1, result.n)
end
end
end
else

View File

@ -1,6 +1,7 @@
package li.cil.oc.server.fs
import java.io
import java.io.FileNotFoundException
import li.cil.oc.api.fs.Mode
import net.minecraft.nbt.NBTTagCompound
@ -45,17 +46,22 @@ trait Buffered extends OutputStreamFileSystem {
else if (!exists(childPath) || !isDirectory(childPath)) {
openOutputHandle(0, childPath, Mode.Write) match {
case Some(stream) =>
val in = new io.FileInputStream(childFile)
val buffer = new Array[Byte](8 * 1024)
var read = 0
do {
read = in.read(buffer)
if (read > 0) {
if (read == buffer.length) stream.write(buffer)
else stream.write(buffer.view(0, read).toArray)
}
} while (read >= 0)
in.close()
try {
val in = new io.FileInputStream(childFile)
val buffer = new Array[Byte](8 * 1024)
var read = 0
do {
read = in.read(buffer)
if (read > 0) {
if (read == buffer.length) stream.write(buffer)
else stream.write(buffer.view(0, read).toArray)
}
} while (read >= 0)
in.close()
}
catch {
case _: FileNotFoundException => // File got deleted in the meantime.
}
stream.close()
setLastModified(childPath, childFile.lastModified())
case _ => // File is open for writing.