From fa6adddcc8df771051a0872b046adab3ca28c943 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Thu, 17 Oct 2024 12:02:26 +0500 Subject: [PATCH] mobile: remove try/catch block --- apps/mobile/app/common/filesystem/io.js | 74 ++++++++++++------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/apps/mobile/app/common/filesystem/io.js b/apps/mobile/app/common/filesystem/io.js index 4f495fb3c..e21b85f8c 100644 --- a/apps/mobile/app/common/filesystem/io.js +++ b/apps/mobile/app/common/filesystem/io.js @@ -193,49 +193,45 @@ export async function deleteDCacheFiles() { } export async function exists(filename) { - try { - let path = `${cacheDir}/${filename}`; + let path = `${cacheDir}/${filename}`; - const iosAppGroup = - Platform.OS === "ios" - ? await RNFetchBlob.fs.pathForAppGroup(IOS_APPGROUPID) - : null; - const appGroupPath = `${iosAppGroup}/${filename}`; + const iosAppGroup = + Platform.OS === "ios" + ? await RNFetchBlob.fs.pathForAppGroup(IOS_APPGROUPID) + : null; + const appGroupPath = `${iosAppGroup}/${filename}`; - let exists = await RNFetchBlob.fs.exists(path); + let 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); - } - - if (exists || existsInAppGroup) { - const attachment = await db.attachments.attachment(filename); - const totalChunks = Math.ceil(attachment.size / attachment.chunkSize); - const totalAbytes = totalChunks * ABYTES; - const expectedFileSize = attachment.size + totalAbytes; - - const stat = await RNFetchBlob.fs.stat( - existsInAppGroup ? appGroupPath : path - ); - - if (stat.size !== expectedFileSize) { - DatabaseLogger.log( - `File size mismatch: ${filename}, expected: ${expectedFileSize}, actual: ${stat.size}` - ); - RNFetchBlob.fs - .unlink(existsInAppGroup ? appGroupPath : path) - .catch(console.log); - return false; - } - - exists = true; - } - return exists; - } catch (e) { - return false; + // Check if file is present in app group path. + let existsInAppGroup = false; + if (!exists && Platform.OS === "ios") { + existsInAppGroup = await RNFetchBlob.fs.exists(appGroupPath); } + + if (exists || existsInAppGroup) { + const attachment = await db.attachments.attachment(filename); + const totalChunks = Math.ceil(attachment.size / attachment.chunkSize); + const totalAbytes = totalChunks * ABYTES; + const expectedFileSize = attachment.size + totalAbytes; + + const stat = await RNFetchBlob.fs.stat( + existsInAppGroup ? appGroupPath : path + ); + + if (stat.size !== expectedFileSize) { + DatabaseLogger.log( + `File size mismatch: ${filename}, expected: ${expectedFileSize}, actual: ${stat.size}` + ); + RNFetchBlob.fs + .unlink(existsInAppGroup ? appGroupPath : path) + .catch(console.log); + return false; + } + + exists = true; + } + return exists; } export async function bulkExists(files) {