From 22987ba96f609d4344611b5d8e8bd1613c652b68 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Wed, 5 Jun 2019 22:04:54 +0200 Subject: [PATCH] #20: Bugfix crash when trying to write to root directory --- .../de/k3b/android/ToGoZip/ZipStorageDocumentFile.java | 7 ++++++- fastlane/metadata/android/en-US/changelogs/20.txt | 1 + libK3b/libK3b.iml | 9 --------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/de/k3b/android/ToGoZip/ZipStorageDocumentFile.java b/app/src/main/java/de/k3b/android/ToGoZip/ZipStorageDocumentFile.java index 70a07a8..334f65b 100644 --- a/app/src/main/java/de/k3b/android/ToGoZip/ZipStorageDocumentFile.java +++ b/app/src/main/java/de/k3b/android/ToGoZip/ZipStorageDocumentFile.java @@ -26,6 +26,7 @@ import android.provider.DocumentsContract; import android.support.v4.provider.DocumentFile; +import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.OutputStream; @@ -158,7 +159,11 @@ public static String getPath(final Context context, final Uri uri) { final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { - return Environment.getExternalStorageDirectory() + "/" + split[1]; + final File externalStorageDirectory = Environment.getExternalStorageDirectory(); + + // split[1] results in index out of bound exception in storage root dir + if (split.length == 1) return externalStorageDirectory.toString(); + return externalStorageDirectory + "/" + split[1]; } // TODO handle non-primary volumes diff --git a/fastlane/metadata/android/en-US/changelogs/20.txt b/fastlane/metadata/android/en-US/changelogs/20.txt index ee2fdbf..b0e2f17 100644 --- a/fastlane/metadata/android/en-US/changelogs/20.txt +++ b/fastlane/metadata/android/en-US/changelogs/20.txt @@ -1 +1,2 @@ +* Bugfix crash when trying to write to root directory #20 * Translation update ar diff --git a/libK3b/libK3b.iml b/libK3b/libK3b.iml index 4404cc8..4373168 100644 --- a/libK3b/libK3b.iml +++ b/libK3b/libK3b.iml @@ -29,16 +29,7 @@ - - - - - - - - - \ No newline at end of file