BlueGit

timfa filemanager

fix: preserve .folder-icons.json across thumbnail cache sync cycles

timfa Tim Falken · pushed by timfa

Authored 2026-05-04 · 6 months ago

Hash
d9c1a9325d92a35ea79bef729487595a82bc5955
Parent
8b75bfe4
2 files changed +22 −0
server/thumbnail-cache.js +1 −0
@@ -175,6 +175,7 @@ async function pruneThumbTree (dirPath, keepFiles)
175 175 }
176 176
177 177 if (full === MANIFEST_PATH || full === MANIFEST_PATH + '.tmp') continue;
178 if (full === FOLDER_ICONS_PATH || full === FOLDER_ICONS_PATH + '.tmp') continue;
178 179 if (!keepFiles.has(path.resolve(full)))
179 180 {
180 181 await removeFileIfExists(full);
@@ -175,6 +175,7 @@ async function pruneThumbTree (dirPath, keepFiles)
175 }
175 }
176
176
177 if (full === MANIFEST_PATH || full === MANIFEST_PATH + '.tmp') continue;
177 if (full === MANIFEST_PATH || full === MANIFEST_PATH + '.tmp') continue;
178 if (full === FOLDER_ICONS_PATH || full === FOLDER_ICONS_PATH + '.tmp') continue;
178 if (!keepFiles.has(path.resolve(full)))
179 if (!keepFiles.has(path.resolve(full)))
179 {
180 {
180 await removeFileIfExists(full);
181 await removeFileIfExists(full);
tests/thumbnail-cache.test.js +21 −0
@@ -96,4 +96,25 @@ describe('thumbnail cache worker', () =>
96 96
97 97 expect(fs.existsSync(thumbPath)).toBe(false);
98 98 });
99
100 test('preserves folder-icons.json across sync cycles', async () =>
101 {
102 const mod = loadModule();
103
104 // Run one sync to create the thumbs dir.
105 await mod.syncThumbnailCacheOnce();
106
107 // Write a folder icon assignment directly.
108 await mod.setFolderIconAssignment(sourceRoot, path.join(sourceRoot, 'cover.jpg'));
109
110 const iconsPath = path.join(thumbsDir, '.folder-icons.json');
111 expect(fs.existsSync(iconsPath)).toBe(true);
112
113 // Run sync again — the file must survive pruning.
114 await mod.syncThumbnailCacheOnce();
115
116 expect(fs.existsSync(iconsPath)).toBe(true);
117 const stored = JSON.parse(fs.readFileSync(iconsPath, 'utf8'));
118 expect(stored[path.resolve(sourceRoot)]).toBe(path.join(sourceRoot, 'cover.jpg'));
119 });
99 120 });
@@ -96,4 +96,25 @@ describe('thumbnail cache worker', () =>
96
96
97 expect(fs.existsSync(thumbPath)).toBe(false);
97 expect(fs.existsSync(thumbPath)).toBe(false);
98 });
98 });
99
100 test('preserves folder-icons.json across sync cycles', async () =>
101 {
102 const mod = loadModule();
103
104 // Run one sync to create the thumbs dir.
105 await mod.syncThumbnailCacheOnce();
106
107 // Write a folder icon assignment directly.
108 await mod.setFolderIconAssignment(sourceRoot, path.join(sourceRoot, 'cover.jpg'));
109
110 const iconsPath = path.join(thumbsDir, '.folder-icons.json');
111 expect(fs.existsSync(iconsPath)).toBe(true);
112
113 // Run sync again — the file must survive pruning.
114 await mod.syncThumbnailCacheOnce();
115
116 expect(fs.existsSync(iconsPath)).toBe(true);
117 const stored = JSON.parse(fs.readFileSync(iconsPath, 'utf8'));
118 expect(stored[path.resolve(sourceRoot)]).toBe(path.join(sourceRoot, 'cover.jpg'));
119 });
99});
120});