mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-12 22:16:05 +09:00
editing file in tevd will update its modification date
This commit is contained in:
@@ -10,7 +10,7 @@ if (exec_args[1] === undefined) {
|
|||||||
|
|
||||||
let noNewFile = (exec_args[1] == "/c" || exec_args[1] == "/C");
|
let noNewFile = (exec_args[1] == "/c" || exec_args[1] == "/C");
|
||||||
let file = files.open(`${_G.shell.resolvePathInput(exec_args[2] || exec_args[1]).full}`)
|
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");
|
printerrln("TOUCH: Can't open "+file.fullPath+" due to IO error");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) {
|
|||||||
fun appendBytes(bytes: ByteArray) {
|
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
|
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)
|
fileContent.getContent().appendBytes(bytes)
|
||||||
|
VDUtil.getFile(DOM, vdPath)!!.modificationDate = VDUtil.currentUnixtime
|
||||||
}
|
}
|
||||||
|
|
||||||
fun writeBytes(bytes: ByteArray) {
|
fun writeBytes(bytes: ByteArray) {
|
||||||
@@ -46,6 +47,7 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) {
|
|||||||
// println("Old: ${fileContent.getContent().toByteArray().toString(VM.CHARSET)}")
|
// println("Old: ${fileContent.getContent().toByteArray().toString(VM.CHARSET)}")
|
||||||
fileContent.replaceContent(ByteArray64.fromByteArray(bytes))
|
fileContent.replaceContent(ByteArray64.fromByteArray(bytes))
|
||||||
// println("New: ${fileContent.getContent().toByteArray().toString(VM.CHARSET)}")
|
// 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
|
return VDUtil.getFile(DOM, vdPath) != null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun delete() {
|
fun delete(): Boolean {
|
||||||
VDUtil.deleteFile(DOM, vdPath)
|
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 {
|
fun length(): Long {
|
||||||
@@ -110,7 +120,9 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) {
|
|||||||
|
|
||||||
fun mkdir(): Boolean {
|
fun mkdir(): Boolean {
|
||||||
return try {
|
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
|
true
|
||||||
}
|
}
|
||||||
catch (e: KotlinNullPointerException) {
|
catch (e: KotlinNullPointerException) {
|
||||||
@@ -123,7 +135,9 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) {
|
|||||||
val time_t = System.currentTimeMillis() / 1000
|
val time_t = System.currentTimeMillis() / 1000
|
||||||
val newFile = DiskEntry(-1, -1, nameBytes, time_t, time_t, fileContent)
|
val newFile = DiskEntry(-1, -1, nameBytes, time_t, time_t, fileContent)
|
||||||
return try {
|
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
|
true
|
||||||
}
|
}
|
||||||
catch (e: KotlinNullPointerException) {
|
catch (e: KotlinNullPointerException) {
|
||||||
|
|||||||
Reference in New Issue
Block a user