Skip to content

Commit 033d951

Browse files
committed
misc: fixes.
1 parent 409ffd9 commit 033d951

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

dfc/src/main/java/com/lazygeniouz/dfc/controller/DocumentController.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ internal class DocumentController(
6464
*/
6565
internal fun isVirtual(): Boolean {
6666
if (!DocumentsContract.isDocumentUri(context, fileUri)) return false
67+
if (fileCompat.documentFlags == -1) return false
6768

6869
return fileCompat.documentFlags and flagVirtualDocument != 0
6970
}
@@ -106,6 +107,7 @@ internal class DocumentController(
106107
) return false
107108

108109
if (fileCompat.documentMimeType.isEmpty()) return false
110+
if (fileCompat.documentFlags == -1) return false
109111

110112
if (fileCompat.documentFlags and Document.FLAG_SUPPORTS_DELETE != 0)
111113
return true

dfc/src/main/java/com/lazygeniouz/dfc/file/internals/RawDocumentFileCompat.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ internal class RawDocumentFileCompat(context: Context, var file: File) :
119119

120120
// Return a file if exists, else **null**
121121
override fun findFile(name: String, ignoreCase: Boolean): DocumentFileCompat? {
122-
return listFiles().firstOrNull { file -> file.name.isNotEmpty() && file.name == name }
122+
return listFiles().firstOrNull { child ->
123+
child.name.equals(name, ignoreCase = ignoreCase)
124+
}
123125
}
124126

125127
// Copies current file to the provided destination uri.

dfc/src/main/java/com/lazygeniouz/dfc/file/internals/SingleDocumentFileCompat.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ internal class SingleDocumentFileCompat(
6464
*
6565
* @throws UnsupportedOperationException
6666
*/
67-
override fun findFile(name: String, ignoreCase: Boolean): DocumentFileCompat {
67+
override fun findFile(name: String, ignoreCase: Boolean): DocumentFileCompat? {
6868
throw UnsupportedOperationException()
6969
}
7070

dfc/src/main/java/com/lazygeniouz/dfc/resolver/ResolverCompat.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ internal object ResolverCompat {
159159
val documentSize = getLongOrDefault(cursor, sizeIndex)
160160
val lastModifiedTime = getLongOrDefault(cursor, modifiedIndex, -1L)
161161
val documentMimeType = getStringOrDefault(cursor, mimeIndex)
162-
val documentFlags = getLongOrDefault(cursor, flagsIndex, -1L).toInt()
162+
163+
/**
164+
* Default flags to 0 (no capabilities) when not included.
165+
* Using `-1` here would make bitwise checks behave as "all flags set".
166+
*/
167+
val documentFlags = getLongOrDefault(cursor, flagsIndex, 0L).toInt()
163168

164169
TreeDocumentFileCompat(
165170
context, documentUri, documentName,

0 commit comments

Comments
 (0)