History

Use pathToFile not string concatenation for dir

Griffin Evans committed 4 months ago

Commit 80a67af1 parent ad2362f2 files · +4 −5Browse files

Unified · Split

2 files
  1. apps/local/src/db/data-dir-ownership.test.ts +1 −1
  2. apps/local/src/db/data-dir-ownership.ts +3 −4
apps/local/src/db/data-dir-ownership.test.ts+1−1
@@ -171,7 +171,7 @@ const runAcquireAttempt = async (dataDir: string): Promise<ChildCloseResult> => · 170 unmodified lines
171171 describe("data-dir ownership", () => {
172172 it("blocks a second process and releases ownership when the holder is SIGKILLed", async () => {
173173 const workDir = mkdtempSync(join(tmpdir(), "executor-data-dir-ownership-"));
174− const dataDir = join(workDir, "data");
174+ const dataDir = join(workDir, "data # owned %3F");
175175 const marker = join(workDir, "owner-ready");
176176 const holder = spawnScript(holderScript, {
177177 EXECUTOR_TEST_DATA_DIR: dataDir,
apps/local/src/db/data-dir-ownership.ts+3−4
@@ -3,6 +3,7 @@ import { createClient, type Client } from "@libsql/client"; · 2 unmodified lines
33 import { Data } from "effect";
44 import { mkdirSync, realpathSync } from "node:fs";
55 import { join, resolve } from "node:path";
6+import { pathToFileURL } from "node:url";
67
78 export class DataDirOwnershipHeld extends Data.TaggedError("DataDirOwnershipHeld")<{
89 readonly message: string;
@@ -17,7 +18,7 @@ export interface DataDirOwnership { · 8 unmodified lines
1718
1819 const LOCK_DATABASE_FILENAME = "data.db.owner-lock";
1920
20−const toLibsqlFileUrl = (path: string): string => `file:${resolve(path)}`;
21+const toLibsqlFileUrl = (path: string): string => pathToFileURL(resolve(path)).href;
2122
2223 const ownerLockPath = (dataDir: string): string => {
2324 mkdirSync(dataDir, { recursive: true });
@@ -63,9 +64,7 @@ const configureOwnershipLockClient = async (client: Client): Promise<void> => { · 39 unmodified lines
6364 await client.execute("PRAGMA journal_mode = DELETE");
6465 };
6566
66−export const acquireDataDirOwnership = async (
67− dataDir: string,
68−): Promise<DataDirOwnership> => {
67+export const acquireDataDirOwnership = async (dataDir: string): Promise<DataDirOwnership> => {
6968 const lockPath = ownerLockPath(dataDir);
7069 const client = openOwnershipLockClient(lockPath);
7170