diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/files/FileUtilsInstrumentationTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/files/FileUtilsInstrumentationTest.kt index 9ea250a816..4466949adf 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/files/FileUtilsInstrumentationTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/files/FileUtilsInstrumentationTest.kt @@ -254,6 +254,14 @@ class FileUtilsInstrumentationTest { DummyUrlData( "https://kiwix.org/contributors/images/wikipedia", null + ), + DummyUrlData( + "https://kiwix.org/contributors/images/wikipedia:hello.epub", + "wikipediahello.epub" + ), + DummyUrlData( + "https://kiwix.org/contributors/Y Gododin: A Poem of the Battle: of Cattraeth.9842.epub", + "Y Gododin A Poem of the Battle of Cattraeth.9842.epub" ) ) dummyUrlArray.forEach { diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml index 1f83796797..0c0ce3e855 100644 --- a/core/src/main/AndroidManifest.xml +++ b/core/src/main/AndroidManifest.xml @@ -39,6 +39,12 @@ + + + + + + diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt index 3acc0833b0..c3e1d8ef8a 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt @@ -410,12 +410,15 @@ object FileUtils { * We are placing a condition here for if the file name does not have a .bin extension, then it returns the original file name. + * Remove colon if any contains in the fileName since most of the fileSystem + will not allow to create file which contains colon in it. + see https://github.com/kiwix/kiwix-android/issues/3737 */ fun getDecodedFileName(url: String?): String? { var fileName: String? = null val decodedFileName = URLUtil.guessFileName(url, null, null) if (!decodedFileName.endsWith(".bin")) { - fileName = decodedFileName + fileName = decodedFileName.replace(":", "") } return fileName } @@ -444,17 +447,8 @@ object FileUtils { ) if (!root.isFileExist()) root.mkdir() } - if (File(root, fileName).isFileExist()) return File(root, fileName) - val fileToSave = sequence { - yield(File(root, fileName)) - yieldAll( - generateSequence(1) { it + 1 }.map { - File( - root, fileName.replace(".", "_$it.") - ) - } - ) - }.first { !it.isFileExist() } + val fileToSave = File(root, fileName) + if (fileToSave.isFileExist()) return fileToSave val source = if (url == null) Uri.parse(src) else Uri.parse(url) return try { zimReaderContainer.load("$source", emptyMap()).data.use { inputStream ->