Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

Fix creating backups ios (#7777)

Ammar Ahmedb8275f5a3faf
diff --git a/apps/mobile/app/common/filesystem/io.ts b/apps/mobile/app/common/filesystem/io.ts
index e28350575..24e6da046 100644
--- a/apps/mobile/app/common/filesystem/io.ts
+++ b/apps/mobile/app/common/filesystem/io.ts
@@ -231,6 +231,26 @@ export async function deleteDCacheFiles() {
}
}
+export async function getCachePathForFile(filename: string) {
+ const path = `${cacheDir}/${filename}`;
+
+ const iosAppGroup =
+ Platform.OS === "ios"
+ ? await (RNFetchBlob.fs as any).pathForAppGroup(IOS_APPGROUPID)
+ : null;
+ const appGroupPath = `${iosAppGroup}/${filename}`;
+
+ const exists = await RNFetchBlob.fs.exists(path);
+
+ // Check if file is present in app group path.
+ let existsInAppGroup = false;
+ if (!exists && Platform.OS === "ios") {
+ existsInAppGroup = await RNFetchBlob.fs.exists(appGroupPath);
+ }
+
+ return existsInAppGroup ? appGroupPath : path;
+}
+
export async function exists(filename: string) {
const path = `${cacheDir}/${filename}`;
diff --git a/apps/mobile/app/services/backup.ts b/apps/mobile/app/services/backup.ts
index 5153834f6..38a372ced 100644
--- a/apps/mobile/app/services/backup.ts
+++ b/apps/mobile/app/services/backup.ts
@@ -39,6 +39,7 @@ import { eCloseSheet } from "../utils/events";
import { sleep } from "../utils/time";
import { ToastManager, eSendEvent, presentSheet } from "./event-manager";
import SettingsService from "./settings";
+import { getCachePathForFile } from "../common/filesystem/io";
const MS_DAY = 86400000;
const MS_WEEK = MS_DAY * 7;
@@ -259,10 +260,14 @@ async function run(
progress: `Saving attachments in backup... ${file.hash}`
});
if (await FileStorage.exists(file.hash)) {
- await RNFetchBlob.fs.cp(
- `${cacheDir}/${file.hash}`,
- `${attachmentsDir}/${file.hash}`
- );
+ await RNFetchBlob.fs
+ .cp(
+ await getCachePathForFile(file.hash),
+ `${attachmentsDir}/${file.hash}`
+ )
+ .catch((e) =>
+ DatabaseLogger.error(e, "Error saving attachment to backup file")
+ );
}
}
}