Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix old asset cache name migration

Abhinavb3ba28499ac4
diff --git a/src/services/diskCache.ts b/src/services/diskCache.ts
index 1056ece215..237c8a8940 100644
--- a/src/services/diskCache.ts
+++ b/src/services/diskCache.ts
@@ -1,10 +1,10 @@
import DiskLRUService from '../services/diskLRU';
import crypto from 'crypto';
-import { existsSync, readFile, unlink } from 'promise-fs';
+import { existsSync, unlink, rename } from 'promise-fs';
import path from 'path';
import { LimitedCache } from '../types/cache';
import { logError } from './logging';
-import { writeStream } from './fs';
+import { getFileStream, writeStream } from './fs';
const DEFAULT_CACHE_LIMIT = 1000 * 1000 * 1000; // 1GB
@@ -27,7 +27,7 @@ export class DiskCache implements LimitedCache {
const cachePath = path.join(this.cacheBucketDir, cacheKey);
if (existsSync(cachePath)) {
DiskLRUService.touch(cachePath);
- return new Response(await readFile(cachePath));
+ return new Response(await getFileStream(cachePath));
} else {
// add fallback for old cache keys
const oldCachePath = getOldAssetCachePath(
@@ -35,8 +35,8 @@ export class DiskCache implements LimitedCache {
cacheKey
);
if (existsSync(oldCachePath)) {
- const match = new Response(await readFile(oldCachePath));
- void migrateOldCacheKey(oldCachePath, cachePath, match);
+ const match = new Response(await getFileStream(oldCachePath));
+ void migrateOldCacheKey(oldCachePath, cachePath);
return match;
}
return undefined;
@@ -62,14 +62,9 @@ function getOldAssetCachePath(cacheDir: string, cacheKey: string) {
return path.join(cacheDir, cacheKeyHash);
}
-async function migrateOldCacheKey(
- oldCacheKey: string,
- newCacheKey: string,
- value: Response
-) {
+async function migrateOldCacheKey(oldCacheKey: string, newCacheKey: string) {
try {
- await this.put(newCacheKey, value);
- await this.delete(oldCacheKey);
+ await rename(oldCacheKey, newCacheKey);
} catch (e) {
logError(e, 'Failed to move cache key to new cache key');
}