Skip to content

Commit 4569980

Browse files
committed
Update SwiftPM for FileSystemError changes in TSC
1 parent d7600df commit 4569980

File tree

5 files changed

+64
-36
lines changed

5 files changed

+64
-36
lines changed

Sources/SPMTestSupport/InMemoryGitRepository.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ extension InMemoryGitRepository: FileSystem {
211211
}
212212

213213
public func changeCurrentWorkingDirectory(to path: AbsolutePath) throws {
214-
throw FileSystemError.unsupported
214+
throw FileSystemError(.unsupported, path)
215215
}
216216

217217
public var homeDirectory: AbsolutePath {
@@ -231,7 +231,7 @@ extension InMemoryGitRepository: FileSystem {
231231
}
232232

233233
public func createSymbolicLink(_ path: AbsolutePath, pointingAt destination: AbsolutePath, relative: Bool) throws {
234-
throw FileSystemError.unsupported
234+
throw FileSystemError(.unsupported, path)
235235
}
236236

237237
public func readFileContents(_ path: AbsolutePath) throws -> ByteString {

Sources/SourceControl/GitRepository.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,15 @@ private class GitFileSystemView: FileSystem {
638638
// Walk the components resolving the tree (starting with a synthetic
639639
// root entry).
640640
var current: Tree.Entry = Tree.Entry(hash: root, type: .tree, name: "/")
641+
var currentPath = AbsolutePath.root
641642
for component in path.components.dropFirst(1) {
642643
// Skip the root pseudo-component.
643644
if component == "/" { continue }
644645

646+
currentPath = currentPath.appending(component: component)
645647
// We have a component to resolve, so the current entry must be a tree.
646648
guard current.type == .tree else {
647-
throw FileSystemError.notDirectory
649+
throw FileSystemError(.notDirectory, currentPath)
648650
}
649651

650652
// Fetch the tree.
@@ -733,21 +735,21 @@ private class GitFileSystemView: FileSystem {
733735

734736
func getDirectoryContents(_ path: AbsolutePath) throws -> [String] {
735737
guard let entry = try getEntry(path) else {
736-
throw FileSystemError.noEntry
738+
throw FileSystemError(.noEntry, path)
737739
}
738740
guard entry.type == .tree else {
739-
throw FileSystemError.notDirectory
741+
throw FileSystemError(.notDirectory, path)
740742
}
741743

742744
return try getTree(entry.hash).contents.map({ $0.name })
743745
}
744746

745747
func readFileContents(_ path: AbsolutePath) throws -> ByteString {
746748
guard let entry = try getEntry(path) else {
747-
throw FileSystemError.noEntry
749+
throw FileSystemError(.noEntry, path)
748750
}
749751
guard entry.type != .tree else {
750-
throw FileSystemError.isDirectory
752+
throw FileSystemError(.isDirectory, path)
751753
}
752754
guard entry.type != .symlink else {
753755
fatalError("FIXME: not implemented")
@@ -766,27 +768,27 @@ private class GitFileSystemView: FileSystem {
766768
}
767769

768770
func createDirectory(_ path: AbsolutePath) throws {
769-
throw FileSystemError.unsupported
771+
throw FileSystemError(.unsupported, path)
770772
}
771773

772774
func createDirectory(_ path: AbsolutePath, recursive: Bool) throws {
773-
throw FileSystemError.unsupported
775+
throw FileSystemError(.unsupported, path)
774776
}
775777

776778
func createSymbolicLink(_ path: AbsolutePath, pointingAt destination: AbsolutePath, relative: Bool) throws {
777-
throw FileSystemError.unsupported
779+
throw FileSystemError(.unsupported, path)
778780
}
779781

780782
func writeFileContents(_ path: AbsolutePath, bytes: ByteString) throws {
781-
throw FileSystemError.unsupported
783+
throw FileSystemError(.unsupported, path)
782784
}
783785

784786
func removeFileTree(_ path: AbsolutePath) throws {
785-
throw FileSystemError.unsupported
787+
throw FileSystemError(.unsupported, path)
786788
}
787789

788790
func chmod(_ mode: FileMode, path: AbsolutePath, options: Set<FileMode.Option>) throws {
789-
throw FileSystemError.unsupported
791+
throw FileSystemError(.unsupported, path)
790792
}
791793

792794
func copy(from sourcePath: AbsolutePath, to destinationPath: AbsolutePath) throws {

Sources/Workspace/Diagnostics.swift

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,44 @@ extension Diagnostic.Message {
158158
extension FileSystemError: CustomStringConvertible {
159159

160160
public var description: String {
161-
switch self {
161+
guard let path = path else {
162+
switch self.kind {
163+
case .invalidAccess:
164+
return "invalid access"
165+
case .ioError:
166+
return "encountered I/O error"
167+
case .isDirectory:
168+
return "is a directory"
169+
case .noEntry:
170+
return "doesn't exist in file system"
171+
case .notDirectory:
172+
return "is not a directory"
173+
case .unsupported:
174+
return "unsupported operation"
175+
case .unknownOSError:
176+
return "unknown system error"
177+
case .alreadyExistsAtDestination:
178+
return "already exists in file system"
179+
}
180+
}
181+
182+
switch self.kind {
162183
case .invalidAccess:
163-
return "invalid access"
184+
return "invalid access to \(path)"
164185
case .ioError:
165-
return "encountered I/O error"
186+
return "encountered an I/O error while reading \(path)"
166187
case .isDirectory:
167-
return "is a directory"
188+
return "\(path) is a directory"
168189
case .noEntry:
169-
return "doesn't exist in file system"
190+
return "\(path) doesn't exist in file system"
170191
case .notDirectory:
171-
return "is not a directory"
192+
return "\(path) is not a directory"
172193
case .unsupported:
173-
return "unsupported operation"
194+
return "unsupported operation on \(path)"
174195
case .unknownOSError:
175-
return "unknown system error"
196+
return "unknown system error while operating on \(path)"
176197
case .alreadyExistsAtDestination:
177-
return "already exists in file system"
198+
return "\(path) already exists in file system"
178199
}
179200
}
180201
}

Tests/SourceControlTests/GitRepositoryTests.swift

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,31 +208,36 @@ class GitRepositoryTests: XCTestCase {
208208
XCTAssert(view.isExecutableFile(AbsolutePath("/test-file-3.sh")))
209209

210210
// Check read of a directory.
211+
let subdirPath = AbsolutePath("/subdir")
211212
XCTAssertEqual(try view.getDirectoryContents(AbsolutePath("/")).sorted(), ["file.swift", "subdir", "test-file-1.txt", "test-file-3.sh"])
212-
XCTAssertEqual(try view.getDirectoryContents(AbsolutePath("/subdir")).sorted(), ["test-file-2.txt"])
213-
XCTAssertThrows(FileSystemError.isDirectory) {
214-
_ = try view.readFileContents(AbsolutePath("/subdir"))
213+
XCTAssertEqual(try view.getDirectoryContents(subdirPath).sorted(), ["test-file-2.txt"])
214+
XCTAssertThrows(FileSystemError(.isDirectory, subdirPath)) {
215+
_ = try view.readFileContents(subdirPath)
215216
}
216217

217218
// Check read versus root.
218-
XCTAssertThrows(FileSystemError.isDirectory) {
219-
_ = try view.readFileContents(AbsolutePath("/"))
219+
XCTAssertThrows(FileSystemError(.isDirectory, .root)) {
220+
_ = try view.readFileContents(.root)
220221
}
221222

222223
// Check read through a non-directory.
223-
XCTAssertThrows(FileSystemError.notDirectory) {
224-
_ = try view.getDirectoryContents(AbsolutePath("/test-file-1.txt"))
224+
let notDirectoryPath1 = AbsolutePath("/test-file-1.txt")
225+
XCTAssertThrows(FileSystemError(.notDirectory, notDirectoryPath1)) {
226+
_ = try view.getDirectoryContents(notDirectoryPath1)
225227
}
226-
XCTAssertThrows(FileSystemError.notDirectory) {
227-
_ = try view.readFileContents(AbsolutePath("/test-file-1.txt/thing"))
228+
let notDirectoryPath2 = AbsolutePath("/test-file-1.txt/thing")
229+
XCTAssertThrows(FileSystemError(.notDirectory, notDirectoryPath2)) {
230+
_ = try view.readFileContents(notDirectoryPath2)
228231
}
229232

230233
// Check read/write into a missing directory.
231-
XCTAssertThrows(FileSystemError.noEntry) {
232-
_ = try view.getDirectoryContents(AbsolutePath("/does-not-exist"))
234+
let noEntryPath1 = AbsolutePath("/does-not-exist")
235+
XCTAssertThrows(FileSystemError(.noEntry, noEntryPath1)) {
236+
_ = try view.getDirectoryContents(noEntryPath1)
233237
}
234-
XCTAssertThrows(FileSystemError.noEntry) {
235-
_ = try view.readFileContents(AbsolutePath("/does/not/exist"))
238+
let noEntryPath2 = AbsolutePath("/does/not/exist")
239+
XCTAssertThrows(FileSystemError(.noEntry, noEntryPath2)) {
240+
_ = try view.readFileContents(noEntryPath2)
236241
}
237242

238243
// Check read of a file.

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3030,7 +3030,7 @@ final class WorkspaceTests: XCTestCase {
30303030
result.check(targets: "Foo")
30313031
}
30323032
DiagnosticsEngineTester(diagnostics) { result in
3033-
result.check(diagnostic: .contains("the package at '/tmp/ws/pkgs/Bar' cannot be accessed (doesn't exist in file system"), behavior: .error)
3033+
result.check(diagnostic: .contains("the package at '/tmp/ws/pkgs/Bar' cannot be accessed (/tmp/ws/pkgs/Bar doesn't exist in file system"), behavior: .error)
30343034
}
30353035
}
30363036
}

0 commit comments

Comments
 (0)