fix: faulty vfs.rename on search
Massimo Melina committed
May 4, 2025 at 15:43 UTC
aaf31ea688d177c371e8bbb27d39775b1d3ab385
3 files changed
+12
-9
e2e/frontend.spec.ts
+1
-1
@@ -111,7 +111,7 @@ test('search1', async ({ page }) => {
111
await page.getByRole('button', { name: 'Search' }).click();
112
await page.locator('input[name="name"]').fill('a');
113
await page.getByRole('button', { name: 'Continue' }).click();
114
- await page.getByText('files, 12 folders, 23 KB').click();
114
+ await page.getByText('files, 12 folders, 29.3 KB').click();
115
await page.getByRole('link', { name: 'cantListPage/ alfa.txt' }).click();
116
await page.getByRole('button', { name: 'Close' }).click();
117
await page.getByRole('button', { name: 'Clear search' }).click();
src/vfs.ts
+10
-8
@@ -4,7 +4,7 @@ import fs from 'fs/promises'
4
import { basename, dirname, join, resolve } from 'path'
5
import {
6
makeMatcher, setHidden, onlyTruthy, isValidFileName, throw_, VfsPerms, Who,
7
- isWhoObject, WHO_ANY_ACCOUNT, defaultPerms, PERM_KEYS, removeStarting, HTTP_SERVER_ERROR, try_, matches
7
+ isWhoObject, WHO_ANY_ACCOUNT, defaultPerms, PERM_KEYS, removeStarting, HTTP_SERVER_ERROR, try_, matches, with_
8
} from './misc'
9
import Koa from 'koa'
10
import _ from 'lodash'
@@ -327,6 +327,7 @@ export async function* walkNode(parent: VfsNode, {
327
try {
328
let lastDir = prefixPath.slice(0, -1) || '.'
329
parentsCache.set(lastDir, parent)
330
+ const root = parent
331
await walkDir(source, { depth, ctx, hidden: showHiddenFiles.get(), parallelizeRecursion }, async entry => {
332
if (ctx?.isAborted()) {
333
stream.push(null)
@@ -334,7 +335,13 @@ export async function* walkNode(parent: VfsNode, {
335
}
336
const {path} = entry
337
const isFolder = entry.isDirectory()
337
- const name = prefixPath + (parent.rename?.[path] || path)
338
+ let renamed = root.rename?.[path]
339
+ if (renamed) {
340
+ const dir = dirname(path) // if `path` isn't just the name, copy its dir in renamed
341
+ if (dir !== '.')
342
+ renamed = dir + '/' + renamed
343
+ }
344
+ const name = prefixPath + (renamed || path)
345
if (usingDescriptIon() && basename(name) === DESCRIPT_ION)
346
return
347
if (taken?.has(normalizeFilename(name))) // taken by vfs node above
@@ -345,12 +352,7 @@ export async function* walkNode(parent: VfsNode, {
352
parent = parentsCache.get(lastDir = dir)
353
}
354
348
- const item: VfsNode = {
349
- name,
350
- isFolder,
351
- source: join(source, path),
352
- rename: renameUnderPath(parent.rename, path),
353
- }
355
+ const item: VfsNode = { name, isFolder, source: join(source, path) }
356
if (await cantSee(item)) // can't see: don't produce and don't recur
357
return false
358
if (onlyFiles ? !isFolder : (!onlyFolders || isFolder))
tests/test.ts
+1
@@ -98,6 +98,7 @@ describe('basics', () => {
98
test('renameChild.get', req('/renameChild/tests/renamed1', /abc/))
99
test('renameChild.deeper', reqList('/renameChild/tests/page', { inList:['renamed2'] }))
100
test('renameChild.get deeper', req('/renameChild/tests/page/renamed2', /PNG/))
101
+ test('renameChild.search', reqList('/renameChild/tests', { inList:['renamed1', 'page/renamed2'] }, { search: 'ren' }))
102
103
test('cantSeeThis', reqList('/', { outList:['cantSeeThis/'] }))
104
test('cantSeeThis.children', reqList('/cantSeeThis', { outList:['hi/'] }))