diff --git a/server/__tests__/archive_service_streaming.test.ts b/server/__tests__/archive_service_streaming.test.ts index f06b0b4fa..01b2d4f32 100644 --- a/server/__tests__/archive_service_streaming.test.ts +++ b/server/__tests__/archive_service_streaming.test.ts @@ -7,7 +7,8 @@ vi.mock("../logger.js", () => ({ logger: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() }, })); -describe("ArchiveService streamed listings", () => { +// The fake 7z/unrar binaries are `#!node` scripts, which Windows cannot execute. +describe.skipIf(process.platform === "win32")("ArchiveService streamed listings", () => { let directory: string; let binary: string; diff --git a/server/__tests__/backup_restore.test.ts b/server/__tests__/backup_restore.test.ts index c52123759..d0d006d75 100644 --- a/server/__tests__/backup_restore.test.ts +++ b/server/__tests__/backup_restore.test.ts @@ -32,7 +32,7 @@ beforeEach(() => { afterEach(() => { delete process.env.BACKUP_DIR; delete process.env.TEST_CONFIG_DIR; - fs.rmSync(tmp, { recursive: true, force: true }); + fs.rmSync(tmp, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }); }); async function zipOf(file: string, entries: Record): Promise { @@ -85,6 +85,12 @@ describe.each(activeTestDialects())("backup and restore on %s", (name) => { afterEach(async () => { await t?.teardown(); + if (name === "sqlite") { + // closeDatabase() is a no-op on SQLite, and Windows refuses to delete a file that is + // still open, so release the handle before the outer hook removes the temp directory. + const { pool } = await import("../db.js"); + pool.close(); + } delete process.env.TEST_DB_FILE; }); @@ -118,7 +124,10 @@ describe.each(activeTestDialects())("backup and restore on %s", (name) => { expect(created.manifest.tables.games).toBe(1); expect(created.manifest.migrations.applied).toBeGreaterThan(0); expect(created.manifest.files.every((f) => /^[0-9a-f]{64}$/.test(f.sha256))).toBe(true); - expect(fs.statSync(path.join(process.env.BACKUP_DIR!, created.name)).mode & 0o077).toBe(0); + // POSIX permission bits do not exist on Windows. + if (process.platform !== "win32") { + expect(fs.statSync(path.join(process.env.BACKUP_DIR!, created.name)).mode & 0o077).toBe(0); + } const list = await svc.listBackups(); expect(list).toHaveLength(1); diff --git a/server/install-version.ts b/server/install-version.ts index 229b60b47..1d6090763 100644 --- a/server/install-version.ts +++ b/server/install-version.ts @@ -22,6 +22,8 @@ const NFO_VERSION = /^[ \t]*version\b[\s:.=-]*v?\s?(?=(\d+(?:\.\d+)+))\1(?![\w.] async function readSmallText(file: string): Promise { let handle: fs.promises.FileHandle | undefined; try { + // O_NOFOLLOW is ignored on Windows, so refuse a link up front on every platform. + if (!(await fs.promises.lstat(file)).isFile()) return null; // O_NOFOLLOW: a symlink (also one swapped in after a check) is never opened. The size is // checked on the opened file and the read itself is bounded, so a file that grows or is // replaced meanwhile can't allocate more than the limit.