mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
dummix dumbshell: fixed erratic 'cd' behaviours
Former-commit-id: 82698355d2566d579d2461bc1f1b7a4799f60163 Former-commit-id: 033a2a4f690b8e968e7626c46b998e3bba91031a
This commit is contained in:
@@ -9,6 +9,7 @@ import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
||||
import net.torvald.terrarum.virtualcomputer.luaapi.Term.Companion.checkIBM437
|
||||
import java.io.*
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.NoSuchFileException
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
@@ -145,6 +146,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Don't use this. Use isFile */
|
||||
class FileExists(val computer: BaseTerrarumComputer) : OneArgFunction() {
|
||||
override fun call(path: LuaValue) : LuaValue {
|
||||
Filesystem.ensurePathSanity(path)
|
||||
@@ -165,7 +167,23 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
|
||||
override fun call(path: LuaValue) : LuaValue {
|
||||
Filesystem.ensurePathSanity(path)
|
||||
|
||||
return LuaValue.valueOf(!Files.isDirectory(Paths.get(computer.getRealPath(path)).toAbsolutePath()))
|
||||
// check if the path is file by checking:
|
||||
// 1. isfile
|
||||
// 2. canwrite
|
||||
// 3. length
|
||||
// Why? Our Java simply wants to fuck you.
|
||||
|
||||
val path = Paths.get(computer.getRealPath(path)).toAbsolutePath()
|
||||
var result = false
|
||||
result = Files.isRegularFile(path)
|
||||
|
||||
if (!result) result = Files.isWritable(path)
|
||||
|
||||
if (!result)
|
||||
try { result = Files.size(path) > 0 }
|
||||
catch (e: NoSuchFileException) { result = false }
|
||||
|
||||
return LuaValue.valueOf(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user