editing file in tevd will update its modification date

This commit is contained in:
minjaesong
2022-12-20 17:28:50 +09:00
parent f1343a91f5
commit a7b3f5a5bf
2 changed files with 19 additions and 5 deletions

View File

@@ -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;
}

View File

@@ -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) {