Skip to content

Commit 342afda

Browse files
committed
fix(pi-sync): allow preflighted path type changes
1 parent 27aae33 commit 342afda

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

extensions/pi-sync/src/sync.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,20 +1036,23 @@ async function preflightSnapshotMutations(
10361036
root: string,
10371037
plan: { deletes: string[]; writes: Array<{ target: string; content: Buffer }> },
10381038
) {
1039+
const deletePaths = new Set(plan.deletes);
10391040
for (const target of plan.deletes) {
10401041
await assertNoSymlinkParents(root, target);
10411042
}
10421043
for (const item of plan.writes) {
1043-
await prepareSnapshotWrite(root, item.target);
1044+
await prepareSnapshotWrite(root, item.target, deletePaths);
10441045
}
10451046
}
10461047

1047-
async function prepareSnapshotWrite(root: string, target: string) {
1048+
async function prepareSnapshotWrite(root: string, target: string, deletePaths: Set<string>) {
10481049
await ensureSafeDirectory(root, path.dirname(target));
10491050
try {
10501051
const stat = await fs.lstat(target);
10511052
if (stat.isSymbolicLink()) throw new Error(`Refusing to overwrite symlink during snapshot apply: ${target}`);
1052-
if (stat.isDirectory()) throw new Error(`Refusing to overwrite directory during snapshot apply: ${target}`);
1053+
if (stat.isDirectory() && !deletePaths.has(target)) {
1054+
throw new Error(`Refusing to overwrite directory during snapshot apply: ${target}`);
1055+
}
10531056
} catch (error) {
10541057
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
10551058
}

0 commit comments

Comments
 (0)