Skip to content
TypeScript

fix(server): cloning into a new folder directly under a drive root no longer fails (#18265)

Pujitha Paladugud5e6f69810c0
diff --git a/apps/server/src/sourceControl/SourceControlRepositoryService.test.ts b/apps/server/src/sourceControl/SourceControlRepositoryService.test.ts
index cbce130dcc8..fca680111c8 100644
--- a/apps/server/src/sourceControl/SourceControlRepositoryService.test.ts
+++ b/apps/server/src/sourceControl/SourceControlRepositoryService.test.ts
@@ -270,13 +270,14 @@ it.effect("keeps arbitrary Bitbucket request failures out of the repository mess
}),
);
-it.effect("clones a looked-up repository into the requested destination", () =>
+it.effect("clones a looked-up repository after creating missing parent directories", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
- const parent = yield* fs.makeTempDirectoryScoped({
+ const temporaryDirectory = yield* fs.makeTempDirectoryScoped({
prefix: "t3-source-control-clone-parent-",
});
+ const parent = path.join(temporaryDirectory, "missing", "nested");
const destinationPath = path.join(parent, "t3code");
const cloneCalls: Array<{ cwd: string; args: ReadonlyArray<string> }> = [];
@@ -305,7 +306,8 @@ it.effect("clones a looked-up repository into the requested destination", () =>
layer({
git: {
execute: (input) =>
- Effect.sync(() => {
+ Effect.gen(function* () {
+ assert.isTrue(yield* fs.exists(parent).pipe(Effect.orDie));
cloneCalls.push({ cwd: input.cwd, args: input.args });
return processOutput();
}),
@@ -528,6 +530,45 @@ it.effect("preserves destination probe failures instead of treating them as miss
);
});
+it.effect("clones directly under an existing filesystem root without recreating it", () =>
+ Effect.gen(function* () {
+ const path = yield* Path.Path;
+ const root = path.parse(path.resolve(".")).root;
+ const cloneCalls: Array<string> = [];
+
+ yield* Effect.gen(function* () {
+ const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
+ yield* service.cloneRepository({
+ provider: SourceControlProviderKind.make("github"),
+ repository: "octocat/t3code",
+ destinationPath: path.join(root, "t3code"),
+ protocol: "https",
+ });
+
+ assert.deepStrictEqual(cloneCalls, [root]);
+ }).pipe(
+ Effect.provide(
+ layer({
+ fileSystem: FileSystem.makeNoop({
+ exists: (target) => Effect.succeed(target === root),
+ makeDirectory: (target) =>
+ Effect.sync(() => {
+ assert.notStrictEqual(target, root, "must not try to create the existing root");
+ }),
+ }),
+ git: {
+ execute: (input) =>
+ Effect.sync(() => {
+ cloneCalls.push(input.cwd);
+ return processOutput();
+ }),
+ },
+ }),
+ ),
+ );
+ }).pipe(Effect.provide(NodePath.layer)),
+);
+
it.effect("publishes by creating the repository, adding a remote, and pushing upstream", () => {
const createCalls: Array<{ cwd: string; repository: string; visibility: string }> = [];
const remoteCalls: Array<{ cwd: string; preferredName: string; url: string }> = [];
diff --git a/apps/server/src/sourceControl/SourceControlRepositoryService.ts b/apps/server/src/sourceControl/SourceControlRepositoryService.ts
index fb59349749a..bca8279ef2e 100644
--- a/apps/server/src/sourceControl/SourceControlRepositoryService.ts
+++ b/apps/server/src/sourceControl/SourceControlRepositoryService.ts
@@ -262,7 +262,11 @@ export const make = Effect.gen(function* () {
});
}
} else {
- yield* fileSystem.makeDirectory(path.dirname(normalizedDestination), { recursive: true });
+ // Skip existing parents: recursive mkdir on a Windows drive root fails with EPERM.
+ const parentPath = path.dirname(normalizedDestination);
+ if (!(yield* fileSystem.exists(parentPath))) {
+ yield* fileSystem.makeDirectory(parentPath, { recursive: true });
+ }
}
return {