diff --git a/packages/storage/storage-json/src/per-record-unit.ts b/packages/storage/storage-json/src/per-record-unit.ts index 78e948edda..83ee6dcc45 100644 --- a/packages/storage/storage-json/src/per-record-unit.ts +++ b/packages/storage/storage-json/src/per-record-unit.ts @@ -143,7 +143,7 @@ async function migrateLegacyUnit(descriptor: KvUnitDescriptor, dir: string, stat /** Read one declared table's record documents into `records`. */ async function loadTableRecords(records: Map, version: number, dir: string): Promise { for (const file of await readdir(dir, { withFileTypes: true })) { - if (!file.isFile() || !file.name.endsWith('.json')) continue + if (!file.name.endsWith('.json')) continue const key = file.name.slice(0, -'.json'.length) if (!SAFE_KEY_RE.test(key)) continue const record = await readRecord(join(dir, file.name), version) diff --git a/packages/storage/storage-json/tests/json-backend.spec.ts b/packages/storage/storage-json/tests/json-backend.spec.ts index 15c172051d..59260b8c03 100644 --- a/packages/storage/storage-json/tests/json-backend.spec.ts +++ b/packages/storage/storage-json/tests/json-backend.spec.ts @@ -1,4 +1,4 @@ -import { chmod, mkdir, mkdtemp, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises' +import { mkdir, mkdtemp, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterAll, describe, expect, it } from 'vitest' @@ -327,17 +327,15 @@ describe('per-record layout', () => { await backend.close() }) - it.skipIf(process.platform === 'win32')('reads an unreadable record document as absent (per-record contract)', async () => { + it('reads an unreadable record document as absent (per-record contract)', async () => { const root = await freshRoot() - const path = recordPath(root, 'locked') - await mkdir(join(root, 'recs', 't'), { recursive: true }) - await writeFile(path, JSON.stringify({ version: 2, record: { v: 1 } }), 'utf8') - await chmod(path, 0o000) + // A directory where the record document should be: readFile fails with + // EISDIR on every platform (permission bits are unenforceable on win32). + await mkdir(join(root, 'recs', 't', 'locked.json'), { recursive: true }) const backend = new JsonStorageBackend(root) const unit = await backend.kv.open(descriptor) expect(await unit.loadAll()).toEqual({ tables: { t: {} }, global: null }) await backend.close() - await chmod(path, 0o600) }) it('migrates a legacy whole-unit file once, new records win, then deletes it', async () => {