Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/__tests__/archive_service_streaming.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 11 additions & 2 deletions server/__tests__/backup_restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>): Promise<void> {
Expand Down Expand Up @@ -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;
});

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions server/install-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const NFO_VERSION = /^[ \t]*version\b[\s:.=-]*v?\s?(?=(\d+(?:\.\d+)+))\1(?![\w.]
async function readSmallText(file: string): Promise<string | null> {
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.
Expand Down
Loading