From d31d9f26385135d32800ee0005d7b90f54fab5a4 Mon Sep 17 00:00:00 2001 From: Zaid Kesarani Date: Sat, 9 May 2020 03:16:12 +0530 Subject: [PATCH] Android: Fixed Export Profile Error (#3082) * Fixed issue: #3010 * solved linter errors * Optimized Code --- .../lib/components/screens/config.js | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/ReactNativeClient/lib/components/screens/config.js b/ReactNativeClient/lib/components/screens/config.js index 886a4c9b87..39612dc684 100644 --- a/ReactNativeClient/lib/components/screens/config.js +++ b/ReactNativeClient/lib/components/screens/config.js @@ -98,31 +98,29 @@ class ConfigScreenComponent extends BaseScreenComponent { this.setState({ profileExportStatus: 'exporting' }); const dbPath = '/data/data/net.cozic.joplin/databases'; - + const exportPath = this.state.profileExportPath; + const resourcePath = `${exportPath}/resources`; try { - await shim.fsDriver().mkdir(this.state.profileExportPath); - await shim.fsDriver().mkdir(`${this.state.profileExportPath}/resources`); { - const files = await shim.fsDriver().readDirStats(dbPath); + const copyFiles = async (source, dest) => { + await shim.fsDriver().mkdir(dest); - for (const file of files) { - const source = `${dbPath}/${file.path}`; - const dest = `${this.state.profileExportPath}/${file.path}`; - reg.logger().info(`Copying profile: ${source} => ${dest}`); - await shim.fsDriver().copy(source, dest); - } - } + const files = await shim.fsDriver().readDirStats(source); - { - const files = await shim.fsDriver().readDirStats(Setting.value('resourceDir')); - - for (const file of files) { - const source = `${Setting.value('resourceDir')}/${file.path}`; - const dest = `${this.state.profileExportPath}/resources/${file.path}`; - reg.logger().info(`Copying profile: ${source} => ${dest}`); - await shim.fsDriver().copy(source, dest); - } + for (const file of files) { + const source_ = `${source}/${file.path}`; + const dest_ = `${dest}/${file.path}`; + if (!file.isDirectory()) { + reg.logger().info(`Copying profile: ${source_} => ${dest_}`); + await shim.fsDriver().copy(source_, dest_); + } else { + await copyFiles(source_, dest_); + } + } + }; + await copyFiles(dbPath, exportPath); + await copyFiles(Setting.value('resourceDir'), resourcePath); } alert('Profile has been exported!');