authorgravatar for git@paperclover.netclover caruso <git@paperclover.net> 2025-10-10 02:45:50-07:00
committergravatar for git@paperclover.netclover caruso <git@paperclover.net> 2025-10-14 02:40:48-07:00
logf171c7f1cd5249ccd190aa99587fe7c3cbb4f209
treea661c7090433416a53c632aca705b7f613921649
parent717f2e02ea1b9f3fe6f53c03100e0a883f688f0e
signature Commit is signed but in an unrecognized format.

fix(site): work around odd file viewer bugs

i've discovered a crash where reviving Lru state failed due to a JSON parsing error. there was also an assertion failure in the Lru implementation, but i think that is unrelated.

1 files changed, 29 insertions(+), 25 deletions(-)

src/file-viewer/cache.ts+29-25
...@@ -61,32 +61,36 @@ const parallelRequests = new Map<string, Promise<http.IncomingMessage>>();...@@ -61,32 +61,36 @@ const parallelRequests = new Map<string, Promise<http.IncomingMessage>>();
6161
62// Revive disk cache state62// Revive disk cache state
63revive: {63revive: {
64 const state = diskCacheState64 try {
65 .readIfExistsSync<Lru.Serialized<string, number>>("json");65 const state = diskCacheState
66 if (!state) break revive;66 .readIfExistsSync<Lru.Serialized<string, number>>("json");
67 const missing = new Set(diskCacheRoot.readDirSync().map((c) => c.base));67 if (!state) break revive;
68 missing.delete(diskCacheState.base);68 const missing = new Set(diskCacheRoot.readDirSync().map((c) => c.base));
69 diskCache.revive(state, {69 missing.delete(diskCacheState.base);
70 map(k: string, v: number) {70 diskCache.revive(state, {
71 const path = new Path(k);71 map(k: string, v: number) {
72 const path = new Path(k);
73 try {
74 const { size } = path.statSync();
75 if (size !== v) return null;
76 if (!missing.delete(k)) return null;
77 return [
78 path,
79 { size, written: new async.Watch(size), memory: new Map() },
80 ];
81 } catch {
82 return null;
83 }
84 },
85 });
86 // Delete unreferenced files
87 for (const missingFile of missing) {
72 try {88 try {
73 const { size } = path.statSync();89 diskCacheRoot.join(missingFile).deleteSync();
74 if (size !== v) return null;90 } catch {}
75 if (!missing.delete(k)) return null;91 }
76 return [92 } catch (err) {
77 path,93 console.warn("Failed to restore file viewer cache", err);
78 { size, written: new async.Watch(size), memory: new Map() },
79 ];
80 } catch {
81 return null;
82 }
83 },
84 });
85 // Delete unreferenced files
86 for (const missingFile of missing) {
87 try {
88 diskCacheRoot.join(missingFile).deleteSync();
89 } catch {}
90 }94 }
91}95}
9296