Skip to content

Commit

Permalink
Improved the getFilePathWithFolderFromUri, and `getFullFilePathFrom…
Browse files Browse the repository at this point in the history
…FilePath` methods to properly resolve the other folders uri.
  • Loading branch information
MohitMaliDeveloper committed Oct 8, 2024
1 parent d1d5a7f commit 7b273c0
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ object FileUtils {
var actualFilePath: String? = null
if (filePath?.isNotEmpty() == true) {
getStorageVolumesList(context).forEach { volume ->
val file = File("$volume/$filePath")
// Check if the volume is part of the file path and remove it
val trimmedFilePath = filePath.removePrefix(volume)
val file = File("$volume/$trimmedFilePath")
if (file.isFileExist()) {
actualFilePath = file.path

Check warning on line 194 in core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt#L194

Added line #L194 was not covered by tests
}
Expand Down Expand Up @@ -284,7 +286,9 @@ object FileUtils {
if (pathSegments.isNotEmpty()) {
// Returns the path of the folder containing the file with the specified fileName,
// from which the user selects the file.
return pathSegments.drop(1).joinToString(separator = "/")
return pathSegments.drop(1)
.filterNot { it.startsWith("0") } // remove the prefix of primary storage device
.joinToString(separator = "/")
}
return null

Check warning on line 293 in core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt#L293

Added line #L293 was not covered by tests
}
Expand Down

0 comments on commit 7b273c0

Please sign in to comment.