Skip to content

Commit

Permalink
Mirrors config migration should not modify user's file (#3901)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
yim-lee authored Dec 2, 2021
1 parent aba6221 commit 4092b74
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Sources/Commands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,11 @@ public class SwiftTool {
let legacyPath = try self.getPackageRoot().appending(components: ".swiftpm", "config")
let newPath = try Workspace.DefaultLocations.mirrorsConfigurationFile(forRootPackage: self.getPackageRoot())
if localFileSystem.exists(legacyPath) {
try localFileSystem.createDirectory(newPath.parentDirectory, recursive: true)
try localFileSystem.move(from: legacyPath, to: newPath)
observabilityScope.emit(warning: "Usage of \(legacyPath) has been deprecated. Please delete it and use the new \(newPath) instead.")
if !localFileSystem.exists(newPath) {
try localFileSystem.createDirectory(newPath.parentDirectory, recursive: true)
try localFileSystem.copy(from: legacyPath, to: newPath)
}
}
return newPath
}
Expand Down

0 comments on commit 4092b74

Please # to comment.