Skip to content

Commit 358c206

Browse files
committed
Consolidate dependency path determination into dedicated APIs
1 parent 8e6b3ec commit 358c206

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Sources/Workspace/Workspace.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ extension Workspace {
10981098

10991099
// Remove the existing checkout.
11001100
do {
1101-
let oldCheckoutPath = self.location.repositoriesCheckoutsDirectory.appending(dependency.subpath)
1101+
let oldCheckoutPath = self.location.repositoriesCheckoutSubdirectory(for: dependency)
11021102
try fileSystem.chmod(.userWritable, path: oldCheckoutPath, options: [.recursive, .onlyFiles])
11031103
try fileSystem.removeFileTree(oldCheckoutPath)
11041104
}
@@ -1136,7 +1136,7 @@ extension Workspace {
11361136
}
11371137

11381138
// Form the edit working repo path.
1139-
let path = self.location.editsDirectory.appending(dependency.subpath)
1139+
let path = self.location.editsSubdirectory(for: dependency)
11401140
// Check for uncommited and unpushed changes if force removal is off.
11411141
if !forceRemove {
11421142
let workingCopy = try repositoryManager.openWorkingCopy(at: path)
@@ -1426,9 +1426,9 @@ extension Workspace {
14261426
public func path(to dependency: Workspace.ManagedDependency) -> AbsolutePath {
14271427
switch dependency.state {
14281428
case .checkout:
1429-
return self.location.repositoriesCheckoutsDirectory.appending(dependency.subpath)
1429+
return self.location.repositoriesCheckoutSubdirectory(for: dependency)
14301430
case .edited(_, let path):
1431-
return path ?? self.location.editsDirectory.appending(dependency.subpath)
1431+
return path ?? self.location.editsSubdirectory(for: dependency)
14321432
case .local:
14331433
return AbsolutePath(dependency.packageRef.location)
14341434
}
@@ -2986,7 +2986,7 @@ extension Workspace {
29862986
/// Removes the clone and checkout of the provided specifier.
29872987
fileprivate func removeRepository(dependency: ManagedDependency) throws {
29882988
// Remove the checkout.
2989-
let dependencyPath = self.location.repositoriesCheckoutsDirectory.appending(dependency.subpath)
2989+
let dependencyPath = self.location.repositoriesCheckoutSubdirectory(for: dependency)
29902990
let workingCopy = try self.repositoryManager.openWorkingCopy(at: dependencyPath)
29912991
guard !workingCopy.hasUncommittedChanges() else {
29922992
throw WorkspaceDiagnostics.UncommitedChanges(repositoryPath: dependencyPath)

Sources/Workspace/WorkspaceConfiguration.swift

Lines changed: 10 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 dependency: ManagedDependency) -> AbsolutePath {
47+
self.editsDirectory.appending(dependency.subpath)
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 dependency: ManagedDependency) -> AbsolutePath {
57+
self.repositoriesCheckoutsDirectory.appending(dependency.subpath)
58+
}
59+
5060
/// Path to the downloaded binary artifacts.
5161
public var artifactsDirectory: AbsolutePath {
5262
self.workingDirectory.appending(component: "artifacts")

0 commit comments

Comments
 (0)