Browse Source

Merge pull request #309 from ente-io/fix-uncaught-unlink-error

Ignore file missing error on unlink
Vishnu Mohandas 1 year ago
parent
commit
3b058e4451
1 changed files with 13 additions and 2 deletions
  1. 13 2
      src/services/diskLRU.ts

+ 13 - 2
src/services/diskLRU.ts

@@ -53,8 +53,19 @@ class DiskLRUService {
                     if (size >= maxSize) {
                     if (size >= maxSize) {
                         const leastRecentlyUsed =
                         const leastRecentlyUsed =
                             await this.findLeastRecentlyUsed(cacheDir);
                             await this.findLeastRecentlyUsed(cacheDir);
-
-                        await unlink(leastRecentlyUsed.path);
+                        try {
+                            await unlink(leastRecentlyUsed.path);
+                        } catch (e) {
+                            // ENOENT: File not found
+                            // which can be ignored as we are trying to delete the file anyway
+                            if (e.code !== 'ENOENT') {
+                                logError(
+                                    e,
+                                    'Failed to evict least recently used'
+                                );
+                            }
+                            // ignoring the error, as it would get retried on the next run
+                        }
                         this.evictLeastRecentlyUsed(cacheDir, maxSize);
                         this.evictLeastRecentlyUsed(cacheDir, maxSize);
                     }
                     }
                     resolve(null);
                     resolve(null);