Skip to content

Commit a190263

Browse files
committed
fix(server): preserve shared checkpoint object directory permissions
1 parent f8765ce commit a190263

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎apps/server/src/vcs/GitVcsDriver.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,24 @@ it.effect("checkpoint recovery discovers nested HEAD independently of inherited
281281
const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-git-dir-" });
282282
const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd);
283283
yield* git(["init", "empty"]);
284+
yield* git(["config", "core.sharedRepository", "group"]);
284285
const originalIndex = yield* fs.readFile(path.join(cwd, ".git", "index"));
285286
yield* fs.makeDirectory(path.join(cwd, "inherited-objects"));
286287
yield* Effect.acquireUseRelease(
287288
Effect.sync(() => {
288-
const previous = { gitDir: process.env.GIT_DIR, objects: process.env.GIT_OBJECT_DIRECTORY };
289+
const previous = {
290+
gitDir: process.env.GIT_DIR,
291+
objects: process.env.GIT_OBJECT_DIRECTORY,
292+
umask: process.umask(0o022),
293+
};
289294
process.env.GIT_DIR = path.join(cwd, ".git");
290295
process.env.GIT_OBJECT_DIRECTORY = path.join(cwd, "inherited-objects");
291296
return previous;
292297
}),
293298
() => driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }),
294299
(previous) =>
295300
Effect.sync(() => {
301+
process.umask(previous.umask);
296302
if (previous.gitDir === undefined) delete process.env.GIT_DIR;
297303
else process.env.GIT_DIR = previous.gitDir;
298304
if (previous.objects === undefined) delete process.env.GIT_OBJECT_DIRECTORY;
@@ -302,6 +308,11 @@ it.effect("checkpoint recovery discovers nested HEAD independently of inherited
302308
assert.strictEqual((yield* git(["show", `${checkpointRef}:file.txt`])).stdout, "unstaged\n");
303309
assert.strictEqual((yield* git(["ls-tree", "-r", checkpointRef, "--", "empty"])).stdout, "");
304310
assert.deepEqual(yield* fs.readFile(path.join(cwd, ".git", "index")), originalIndex);
311+
if ((yield* HostProcess.Platform) !== "win32") {
312+
const blob = (yield* git(["rev-parse", `${checkpointRef}:file.txt`])).stdout.trim();
313+
const fanout = yield* fs.stat(path.join(cwd, ".git", "objects", blob.slice(0, 2)));
314+
assert.strictEqual(fanout.mode & 0o020, 0o020);
315+
}
305316
}).pipe(Effect.scoped, Effect.provide(layerGitContract)),
306317
);
307318

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,20 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
916916
function* (cwd: string, from: string, to: string) {
917917
// Per-directory moves share the enclosing publication span.
918918
const move = Effect.fnUntraced(function* (directory: string, names: ReadonlyArray<string>) {
919-
yield* fileSystem.makeDirectory(path.join(to, directory), { recursive: true });
919+
// Keep Git's shared-repository permissions on newly published directories.
920+
const moved = yield* fileSystem
921+
.rename(path.join(from, directory), path.join(to, directory))
922+
.pipe(
923+
Effect.as(true),
924+
Effect.catch((error) =>
925+
fileSystem
926+
.exists(path.join(to, directory))
927+
.pipe(
928+
Effect.flatMap((exists) => (exists ? Effect.succeed(false) : Effect.fail(error))),
929+
),
930+
),
931+
);
932+
if (moved) return;
920933
for (const name of names) {
921934
const target = path.join(to, directory, name);
922935
// Another writer may have published the same read-only object, which Windows won't replace.

0 commit comments

Comments
 (0)