Skip to content

Commit cf5a865

Browse files
committed
[Commands] Cleanup existing symlink when editing
<rdar://problem/38524354> Swift package manager edit path command returns a file exists symlink error despite cleaning up build directory
1 parent e1ff52a commit cf5a865

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Sources/Workspace/Workspace.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,17 @@ extension Workspace {
712712
try fileSystem.createDirectory(editablesPath)
713713
// FIXME: We need this to work with InMem file system too.
714714
if !(fileSystem is InMemoryFileSystem) {
715-
try createSymlink(
716-
editablesPath.appending(component: packageName),
717-
pointingAt: path,
718-
relative: false)
715+
let symLinkPath = editablesPath.appending(component: packageName)
716+
717+
// Cleanup any existing symlink.
718+
if fileSystem.isSymlink(symLinkPath) {
719+
try fileSystem.removeFileTree(symLinkPath)
720+
}
721+
722+
// FIXME: We should probably just warn in case we fail to create
723+
// this symlink, which could happen if there is some non-symlink
724+
// entry at this location.
725+
try createSymlink(symLinkPath, pointingAt: path, relative: false)
719726
}
720727
}
721728

0 commit comments

Comments
 (0)