Skip to content

Commit 4092b74

Browse files
authored
Mirrors config migration should not modify user's file (#3901)
Motivation: The migration from `.swiftpm/config` to `.swiftpm/configuration/mirrors.json` moves `.swiftpm/config` and leads user to think that the file gets deleted. (rdar://85917746) Modifications: - Copy `.swiftpm/config` to `.swiftpm/configuration/mirrors.json` instead of moving it. - Emit warning that `.swiftpm/config` has been deprecated. - Don't perform the migration if `.swiftpm/configuration/mirrors.json` already exists to prevent error. (rdar://85917836)
1 parent aba6221 commit 4092b74

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Sources/Commands/SwiftTool.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,11 @@ public class SwiftTool {
525525
let legacyPath = try self.getPackageRoot().appending(components: ".swiftpm", "config")
526526
let newPath = try Workspace.DefaultLocations.mirrorsConfigurationFile(forRootPackage: self.getPackageRoot())
527527
if localFileSystem.exists(legacyPath) {
528-
try localFileSystem.createDirectory(newPath.parentDirectory, recursive: true)
529-
try localFileSystem.move(from: legacyPath, to: newPath)
528+
observabilityScope.emit(warning: "Usage of \(legacyPath) has been deprecated. Please delete it and use the new \(newPath) instead.")
529+
if !localFileSystem.exists(newPath) {
530+
try localFileSystem.createDirectory(newPath.parentDirectory, recursive: true)
531+
try localFileSystem.copy(from: legacyPath, to: newPath)
532+
}
530533
}
531534
return newPath
532535
}

0 commit comments

Comments
 (0)