diff --git a/assets/disk0/tvdos/bin/touch.js b/assets/disk0/tvdos/bin/touch.js index 1fca32b..40763b1 100644 --- a/assets/disk0/tvdos/bin/touch.js +++ b/assets/disk0/tvdos/bin/touch.js @@ -10,7 +10,7 @@ if (exec_args[1] === undefined) { let noNewFile = (exec_args[1] == "/c" || exec_args[1] == "/C"); let file = files.open(`${_G.shell.resolvePathInput(exec_args[2] || exec_args[1]).full}`) -if (!file.exists) { +if (!file.exists && noNewFile) { printerrln("TOUCH: Can't open "+file.fullPath+" due to IO error"); return 1; } diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt index 33d0b6c..1bcecff 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt @@ -38,6 +38,7 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { fun appendBytes(bytes: ByteArray) { val fileContent = VDUtil.getAsNormalFile(DOM, vdPath) // this is not an object properties: the reference to the file may have been changed fileContent.getContent().appendBytes(bytes) + VDUtil.getFile(DOM, vdPath)!!.modificationDate = VDUtil.currentUnixtime } fun writeBytes(bytes: ByteArray) { @@ -46,6 +47,7 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { // println("Old: ${fileContent.getContent().toByteArray().toString(VM.CHARSET)}") fileContent.replaceContent(ByteArray64.fromByteArray(bytes)) // println("New: ${fileContent.getContent().toByteArray().toString(VM.CHARSET)}") + VDUtil.getFile(DOM, vdPath)!!.modificationDate = VDUtil.currentUnixtime } /** @@ -81,8 +83,16 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { return VDUtil.getFile(DOM, vdPath) != null } - fun delete() { - VDUtil.deleteFile(DOM, vdPath) + fun delete(): Boolean { + return try { + val parentDir = vdPath.getParent() + VDUtil.deleteFile(DOM, vdPath) + VDUtil.getFile(DOM, parentDir)!!.modificationDate = VDUtil.currentUnixtime + true + } + catch (e: KotlinNullPointerException) { + false + } } fun length(): Long { @@ -110,7 +120,9 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { fun mkdir(): Boolean { return try { - VDUtil.addDir(DOM, vdPath.getParent(), nameBytes) + val parentDir = vdPath.getParent() + VDUtil.addDir(DOM, parentDir, nameBytes) + VDUtil.getFile(DOM, parentDir)!!.modificationDate = VDUtil.currentUnixtime true } catch (e: KotlinNullPointerException) { @@ -123,7 +135,9 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { val time_t = System.currentTimeMillis() / 1000 val newFile = DiskEntry(-1, -1, nameBytes, time_t, time_t, fileContent) return try { - VDUtil.addFile(DOM, vdPath.getParent(), newFile) + val parentDir = vdPath.getParent() + VDUtil.addFile(DOM, parentDir, newFile) + VDUtil.getFile(DOM, parentDir)!!.modificationDate = VDUtil.currentUnixtime true } catch (e: KotlinNullPointerException) {