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
171describe("data-dir ownership", () => {171describe("data-dir ownership", () => {
172 it("blocks a second process and releases ownership when the holder is SIGKILLed", async () => {172 it("blocks a second process and releases ownership when the holder is SIGKILLed", async () => {
173 const workDir = mkdtempSync(join(tmpdir(), "executor-data-dir-ownership-"));173 const workDir = mkdtempSync(join(tmpdir(), "executor-data-dir-ownership-"));
174 const dataDir = join(workDir, "data");174 const dataDir = join(workDir, "data # owned %3F");
175 const marker = join(workDir, "owner-ready");175 const marker = join(workDir, "owner-ready");
176 const holder = spawnScript(holderScript, {176 const holder = spawnScript(holderScript, {
177 EXECUTOR_TEST_DATA_DIR: dataDir,177 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
3import { Data } from "effect";3import { Data } from "effect";
4import { mkdirSync, realpathSync } from "node:fs";4import { mkdirSync, realpathSync } from "node:fs";
5import { join, resolve } from "node:path";5import { join, resolve } from "node:path";
6import { pathToFileURL } from "node:url";
6 7
7export class DataDirOwnershipHeld extends Data.TaggedError("DataDirOwnershipHeld")<{8export class DataDirOwnershipHeld extends Data.TaggedError("DataDirOwnershipHeld")<{
8 readonly message: string;9 readonly message: string;
@@ -17,7 +18,7 @@ export interface DataDirOwnership { · 8 unmodified lines
17 18
18const LOCK_DATABASE_FILENAME = "data.db.owner-lock";19const LOCK_DATABASE_FILENAME = "data.db.owner-lock";
19 20
20const toLibsqlFileUrl = (path: string): string => `file:${resolve(path)}`;21const toLibsqlFileUrl = (path: string): string => pathToFileURL(resolve(path)).href;
21 22
22const ownerLockPath = (dataDir: string): string => {23const ownerLockPath = (dataDir: string): string => {
23 mkdirSync(dataDir, { recursive: true });24 mkdirSync(dataDir, { recursive: true });
@@ -63,9 +64,7 @@ const configureOwnershipLockClient = async (client: Client): Promise<void> => { · 39 unmodified lines
63 await client.execute("PRAGMA journal_mode = DELETE");64 await client.execute("PRAGMA journal_mode = DELETE");
64};65};
65 66
66export const acquireDataDirOwnership = async (67export const acquireDataDirOwnership = async (dataDir: string): Promise<DataDirOwnership> => {
67 dataDir: string,
68): Promise<DataDirOwnership> => {
69 const lockPath = ownerLockPath(dataDir);68 const lockPath = ownerLockPath(dataDir);
70 const client = openOwnershipLockClient(lockPath);69 const client = openOwnershipLockClient(lockPath);
71 70