From 53468547f1873941df7da214c2dcad511c8468f9 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Fri, 12 Apr 2024 21:34:17 -0400 Subject: [PATCH] FIX: If file existed, it wouldnt proceed. --- BlueApp.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/BlueApp.ts b/BlueApp.ts index 73b13497f..277ba3771 100644 --- a/BlueApp.ts +++ b/BlueApp.ts @@ -324,7 +324,12 @@ export class AppStorage { * @returns {Promise.} */ async loadFromDisk(password?: string): Promise { - await this.moveRealmFilesToCacheDirectory(); + // Wrap inside a try so if anything goes wrong it wont block loadFromDisk from continuing + try { + await this.moveRealmFilesToCacheDirectory(); + } catch (error: any) { + console.warn('moveRealmFilesToCacheDirectory error:', error.message); + } let data = await this.getItemWithFallbackToRealm('data'); if (password) { data = this.decryptData(data, password); @@ -914,8 +919,14 @@ export class AppStorage { const filePath = `${documentPath}/${file.name}`; const newFilePath = `${cachePath}/${file.name}`; const fileExists = await RNFS.exists(filePath); // Check if the file exists + const cacheFileExists = await RNFS.exists(newFilePath); // Check if the file already exists in the cache directory + if (fileExists) { - await RNFS.moveFile(filePath, newFilePath); // Move the file if it exists + if (cacheFileExists) { + await RNFS.unlink(newFilePath); // Delete the file in the cache directory if it exists + console.log(`Existing file removed from cache: ${newFilePath}`); + } + await RNFS.moveFile(filePath, newFilePath); // Move the file console.log(`Moved Realm file: ${filePath} to ${newFilePath}`); } else { console.log(`File does not exist: ${filePath}`);