Skip to content

Commit 2f79ea2

Browse files
committed
Consolidate dependency path determination into dedicated APIs
1 parent e062529 commit 2f79ea2

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
@@ -1111,7 +1111,7 @@ extension Workspace {
11111111

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

11511151
// Form the edit working repo path.
1152-
let path = self.location.editsDirectory.appending(dependency.subpath)
1152+
let path = self.location.editsSubdirectory(for: dependency.packageRef)
11531153
// Check for uncommited and unpushed changes if force removal is off.
11541154
if !forceRemove {
11551155
let workingCopy = try repositoryManager.openWorkingCopy(at: path)
@@ -1432,9 +1432,9 @@ extension Workspace {
14321432
public func path(to dependency: Workspace.ManagedDependency) -> AbsolutePath {
14331433
switch dependency.state {
14341434
case .checkout:
1435-
return self.location.repositoriesCheckoutsDirectory.appending(dependency.subpath)
1435+
return self.location.repositoriesCheckoutSubdirectory(for: dependency.packageRef)
14361436
case .edited(_, let path):
1437-
return path ?? self.location.editsDirectory.appending(dependency.subpath)
1437+
return path ?? self.location.editsSubdirectory(for: dependency.packageRef)
14381438
case .local:
14391439
return AbsolutePath(dependency.packageRef.location)
14401440
}
@@ -2660,7 +2660,7 @@ extension Workspace {
26602660
private func fetch(package: PackageReference) throws -> AbsolutePath {
26612661
// If we already have it, fetch to update the repo from its remote.
26622662
if let dependency = self.state.dependencies[package] {
2663-
let path = self.location.repositoriesCheckoutsDirectory.appending(dependency.subpath)
2663+
let path = self.location.repositoriesCheckoutSubdirectory(for: dependency.packageRef)
26642664

26652665
// Make sure the directory is not missing (we will have to clone again
26662666
// if not).
@@ -2840,7 +2840,7 @@ extension Workspace {
28402840
}
28412841

28422842
// Remove the checkout.
2843-
let dependencyPath = self.location.repositoriesCheckoutsDirectory.appending(dependencyToRemove.subpath)
2843+
let dependencyPath = self.location.repositoriesCheckoutSubdirectory(for: dependencyToRemove.packageRef)
28442844
let workingCopy = try repositoryManager.openWorkingCopy(at: dependencyPath)
28452845
guard !workingCopy.hasUncommittedChanges() else {
28462846
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)