fix: dispose worktree instance before removal
This commit is contained in:
@@ -18,6 +18,7 @@ export interface Interface {
|
||||
readonly load: (input: LoadInput) => Effect.Effect<InstanceContext>
|
||||
readonly reload: (input: LoadInput) => Effect.Effect<InstanceContext>
|
||||
readonly dispose: (ctx: InstanceContext) => Effect.Effect<void>
|
||||
readonly disposeDirectory: (directory: string) => Effect.Effect<void>
|
||||
readonly disposeAll: () => Effect.Effect<void>
|
||||
readonly provide: <A, E, R>(input: LoadInput, effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
|
||||
}
|
||||
@@ -148,6 +149,16 @@ export const layer: Layer.Layer<Service, never, Project.Service | InstanceBootst
|
||||
yield* disposeEntry(ctx.directory, entry, ctx).pipe(Effect.asVoid)
|
||||
})
|
||||
|
||||
const disposeDirectory = Effect.fn("InstanceStore.disposeDirectory")(function* (directory: string) {
|
||||
const key = AppFileSystem.resolve(directory)
|
||||
const entry = cache.get(key)
|
||||
if (!entry) return
|
||||
|
||||
const exit = yield* Deferred.await(entry.deferred).pipe(Effect.exit)
|
||||
if (Exit.isFailure(exit)) return yield* removeEntry(key, entry).pipe(Effect.asVoid)
|
||||
yield* disposeEntry(key, entry, exit.value).pipe(Effect.asVoid)
|
||||
})
|
||||
|
||||
const disposeAllOnce = Effect.fnUntraced(function* () {
|
||||
yield* Effect.logInfo("disposing all instances")
|
||||
yield* Effect.forEach(
|
||||
@@ -182,6 +193,7 @@ export const layer: Layer.Layer<Service, never, Project.Service | InstanceBootst
|
||||
load,
|
||||
reload,
|
||||
dispose,
|
||||
disposeDirectory,
|
||||
disposeAll,
|
||||
provide,
|
||||
})
|
||||
|
||||
@@ -380,6 +380,7 @@ export const layer: Layer.Layer<
|
||||
throw new NotGitError({ message: "Worktrees are only supported for git projects" })
|
||||
}
|
||||
|
||||
yield* store.disposeDirectory(input.directory).pipe(Effect.ignore)
|
||||
const directory = yield* canonical(input.directory)
|
||||
|
||||
const list = yield* git(["worktree", "list", "--porcelain"], { cwd: ctx.worktree })
|
||||
@@ -393,12 +394,14 @@ export const layer: Layer.Layer<
|
||||
if (!entry?.path) {
|
||||
const directoryExists = yield* fs.exists(directory).pipe(Effect.orDie)
|
||||
if (directoryExists) {
|
||||
yield* store.disposeDirectory(directory).pipe(Effect.ignore)
|
||||
yield* stopFsmonitor(directory)
|
||||
yield* cleanDirectory(directory)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
yield* store.disposeDirectory(entry.path).pipe(Effect.ignore)
|
||||
yield* stopFsmonitor(entry.path)
|
||||
const removed = yield* git(["worktree", "remove", "--force", entry.path], { cwd: ctx.worktree })
|
||||
if (removed.code !== 0) {
|
||||
|
||||
Reference in New Issue
Block a user