Compare commits

...

2 Commits

Author SHA1 Message Date
Ammar Ahmed
72f0a9c476 mobile: catch and show error if copying file fails during backup 2025-02-19 15:02:36 +05:00
Ammar Ahmed
6f9a8de5c2 mobile: fix copying file from app group during backup 2025-02-19 14:46:04 +05:00
2 changed files with 29 additions and 4 deletions

View File

@@ -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}`;

View File

@@ -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")
);
}
}
}