fix(file-cache): try/catch to prevent concurrency issues

This commit is contained in:
Hellyson Rodrigo Parteka 2021-11-30 04:39:40 -03:00
parent 9afca25866
commit 3b2aa47e95
No known key found for this signature in database
GPG key ID: 3055745CA21934C7

View file

@ -58,10 +58,14 @@ export default class FileCacheProvider {
const stats = await fs.stat(tmpPath);
if (stats.size !== 0) {
await fs.rename(tmpPath, finalPath);
}
try {
await fs.rename(tmpPath, finalPath);
await FileCache.create({hash, bytes: stats.size, accessedAt: new Date()});
await FileCache.create({hash, bytes: stats.size, accessedAt: new Date()});
} catch (e: unknown) {
console.error(e);
}
}
await this.evictOldestIfNecessary();
});