Allow directory creation on exposed volumes

This commit is contained in:
Matéo Duparc 2024-01-13 21:41:58 +01:00
parent 5474d6eea5
commit f4e47c1827
Signed by untrusted user: hardcoresushi
GPG Key ID: AFE384344A45E13A

View File

@ -236,14 +236,21 @@ class VolumeProvider: DocumentsProvider() {
): String? { ): String? {
if (!usfExpose || !usfSafWrite) return null if (!usfExpose || !usfSafWrite) return null
val document = parseDocumentId(parentDocumentId) ?: return null val document = parseDocumentId(parentDocumentId) ?: return null
val newFile = PathUtils.pathJoin(document.path, displayName) val path = PathUtils.pathJoin(document.path, displayName)
val f = document.encryptedVolume.openFileWriteMode(newFile) var success = false
return if (f == -1L) { if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR) {
Log.e(TAG, "Failed to create file: $document") success = document.encryptedVolume.mkdir(path)
null
} else { } else {
val f = document.encryptedVolume.openFileWriteMode(path)
if (f != -1L) {
document.encryptedVolume.closeFile(f) document.encryptedVolume.closeFile(f)
document.rootId+newFile success = true
}
}
return if (success) {
document.rootId+path
} else {
null
} }
} }