Skip to content

Commit c3ec774

Browse files
committed
Consolidate dependency path determination into dedicated APIs
1 parent 4062768 commit c3ec774

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

Sources/Workspace/Workspace.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ extension Workspace {
11121112

11131113
// Remove the existing checkout.
11141114
do {
1115-
let oldCheckoutPath = self.location.repositoriesCheckoutsDirectory.appending(dependency.subpath)
1115+
let oldCheckoutPath = self.location.repositoriesCheckoutSubdirectory(for: dependency.packageRef)
11161116
try fileSystem.chmod(.userWritable, path: oldCheckoutPath, options: [.recursive, .onlyFiles])
11171117
try fileSystem.removeFileTree(oldCheckoutPath)
11181118
}
@@ -1150,7 +1150,7 @@ extension Workspace {
11501150
}
11511151

11521152
// Form the edit working repo path.
1153-
let path = self.location.editsDirectory.appending(dependency.subpath)
1153+
let path = self.location.editsSubdirectory(for: dependency.packageRef)
11541154
// Check for uncommited and unpushed changes if force removal is off.
11551155
if !forceRemove {
11561156
let workingCopy = try repositoryManager.openWorkingCopy(at: path)
@@ -1440,9 +1440,9 @@ extension Workspace {
14401440
public func path(to dependency: Workspace.ManagedDependency) -> AbsolutePath {
14411441
switch dependency.state {
14421442
case .checkout:
1443-
return self.location.repositoriesCheckoutsDirectory.appending(dependency.subpath)
1443+
return self.location.repositoriesCheckoutSubdirectory(for: dependency.packageRef)
14441444
case .edited(_, let path):
1445-
return path ?? self.location.editsDirectory.appending(dependency.subpath)
1445+
return path ?? self.location.editsSubdirectory(for: dependency.packageRef)
14461446
case .local:
14471447
return AbsolutePath(dependency.packageRef.location)
14481448
}
@@ -2676,7 +2676,7 @@ extension Workspace {
26762676
// If we already have it, fetch to update the repo from its remote.
26772677
// also compare the location as it may have changed
26782678
if let dependency = self.state.dependencies[comparingLocation: package] {
2679-
let path = self.location.repositoriesCheckoutsDirectory.appending(dependency.subpath)
2679+
let path = self.location.repositoriesCheckoutSubdirectory(for: dependency.packageRef)
26802680

26812681
// Make sure the directory is not missing (we will have to clone again
26822682
// if not).
@@ -2844,7 +2844,7 @@ extension Workspace {
28442844
}
28452845

28462846
// Remove the checkout.
2847-
let dependencyPath = self.location.repositoriesCheckoutsDirectory.appending(dependencyToRemove.subpath)
2847+
let dependencyPath = self.location.repositoriesCheckoutSubdirectory(for: dependencyToRemove.packageRef)
28482848
let workingCopy = try repositoryManager.openWorkingCopy(at: dependencyPath)
28492849
guard !workingCopy.hasUncommittedChanges() else {
28502850
throw WorkspaceDiagnostics.UncommitedChanges(repositoryPath: dependencyPath)

Sources/Workspace/WorkspaceConfiguration.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,21 @@ extension Workspace {
4242
self.workingDirectory.appending(component: "repositories")
4343
}
4444

45+
/// Returns the path to the repository checkout directory for a package.
46+
public func editsSubdirectory(for package: PackageReference) -> AbsolutePath {
47+
self.editsDirectory.appending(subpath(for: package))
48+
}
49+
4550
/// Path to the repository checkouts.
4651
public var repositoriesCheckoutsDirectory: AbsolutePath {
4752
self.workingDirectory.appending(component: "checkouts")
4853
}
4954

55+
/// Returns the path to the repository checkout directory for a package.
56+
public func repositoriesCheckoutSubdirectory(for package: PackageReference) -> AbsolutePath {
57+
self.repositoriesCheckoutsDirectory.appending(subpath(for: package))
58+
}
59+
5060
/// Path to the downloaded binary artifacts.
5161
public var artifactsDirectory: AbsolutePath {
5262
self.workingDirectory.appending(component: "artifacts")
@@ -72,6 +82,10 @@ extension Workspace {
7282
self.sharedConfigurationDirectory.map { DefaultLocations.registriesConfigurationFile(at: $0) }
7383
}
7484

85+
private func subpath(for package: PackageReference) -> RelativePath {
86+
return RelativePath(package.identity.description.lowercased())
87+
}
88+
7589
/// Create a new workspace location.
7690
///
7791
/// - Parameters:

0 commit comments

Comments
 (0)