Added additional logging for Android rename/move

This commit is contained in:
OpenSauce04 2025-12-12 19:57:01 +00:00
parent ec9a782aab
commit 7498682b3c
2 changed files with 20 additions and 5 deletions

View File

@ -683,6 +683,9 @@ object NativeLibrary {
try {
CitraApplication.documentsTree.renameFile(path, destinationFilename)
} catch (e: Exception) {
if (e.message != null) {
Log.error(e.message!!)
}
false
}
} else {
@ -696,6 +699,9 @@ object NativeLibrary {
try {
CitraApplication.documentsTree.moveFile(filename, sourceDirPath, destinationDirPath)
} catch (e: Exception) {
if (e.message != null) {
Log.error(e.message!!)
}
false
}
} else {

View File

@ -192,7 +192,9 @@ class DocumentsTree {
@Synchronized
fun renameFile(filepath: String, destinationFilename: String): Boolean {
val node = resolvePath(filepath) ?: return false
val node = resolvePath(filepath) ?: run {
error("[DocumentsTree]: Failed to resolve path during rename: $filepath")
}
try {
val filename = URLDecoder.decode(destinationFilename, FileUtil.DECODE_METHOD)
val newUri = DocumentsContract.renameDocument(context.contentResolver, node.uri!!, filename)
@ -205,9 +207,16 @@ class DocumentsTree {
@Synchronized
fun moveFile(filename: String, sourceDirPath: String, destDirPath: String): Boolean {
val sourceFileNode = resolvePath(sourceDirPath + "/" + filename) ?: return false
val sourceDirNode = resolvePath(sourceDirPath) ?: return false
val destDirNode = resolvePath(destDirPath) ?: return false
val resolutionErrorMessage = "[DocumentsTree]: Failed to resolve path during move: "
val sourceFileNode = resolvePath(sourceDirPath + "/" + filename) ?: run {
error(resolutionErrorMessage + (sourceDirPath + "/" + filename))
}
val sourceDirNode = resolvePath(sourceDirPath) ?: run {
error(resolutionErrorMessage + sourceDirPath)
}
val destDirNode = resolvePath(destDirPath) ?: run {
error(resolutionErrorMessage + destDirPath)
}
try {
val newUri = DocumentsContract.moveDocument(context.contentResolver, sourceFileNode.uri!!, sourceDirNode.uri!!, destDirNode.uri!!)
sourceFileNode.rename(filename, newUri)
@ -229,7 +238,7 @@ class DocumentsTree {
}
return true
} catch (e: Exception) {
error("[DocumentsTree]: Cannot rename file, error: " + e.message)
error("[DocumentsTree]: Cannot delete file, error: " + e.message)
}
}