From 7254f34e9cfd306320783c8203b7daa003e34e13 Mon Sep 17 00:00:00 2001 From: Lee Houghton Date: Wed, 24 Jun 2020 15:54:58 +0100 Subject: [PATCH 1/2] Improve error message when copyRecursively() fails In my case, this failed on Android 10 due to not having permissions and not having `android:requestLegacyExternalStorage="true"` in `AndroidManifest.xml`. At least if there's a useful error message, it's a starting point for debugging (though perhaps this should be mentioned in the documentation somewhere, either for the FileSystem plugin or for Android configuration - or even for the default template, since the plugins need it to work?) https://commonsware.com/blog/2019/06/07/death-external-storage-end-saga.html --- .../java/com/getcapacitor/plugin/Filesystem.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java index 9cd6923779..5986c8574a 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java @@ -579,23 +579,23 @@ private void _copy(PluginCall call, boolean doRename) { toObject.delete(); assert fromObject != null; - boolean modified = false; if (doRename) { - modified = fromObject.renameTo(toObject); + boolean modified = fromObject.renameTo(toObject); + if (!modified) { + call.error("Unable to rename, unknown reason"); + return; + } } else { try { copyRecursively(fromObject, toObject); modified = true; - } catch (IOException ignored) { + } catch (IOException e) { + call.error("Unable to perform action: " + e.getLocalizedMessage()); + return; } } - if (!modified) { - call.error("Unable to perform action, unknown reason"); - return; - } - call.success(); } From 4faf3b856d59d37f2d4dd19eb8884f5ddfa00659 Mon Sep 17 00:00:00 2001 From: Lee Houghton Date: Wed, 24 Jun 2020 16:01:28 +0100 Subject: [PATCH 2/2] Fix compiler error in last commit --- .../src/main/java/com/getcapacitor/plugin/Filesystem.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java index 5986c8574a..18e62b67ed 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Filesystem.java @@ -589,7 +589,6 @@ private void _copy(PluginCall call, boolean doRename) { } else { try { copyRecursively(fromObject, toObject); - modified = true; } catch (IOException e) { call.error("Unable to perform action: " + e.getLocalizedMessage()); return;