Skip to content

Commit ebf7c43

Browse files
authored
adjust FileSystem implementations to TSC API changes (#3962) (#3965)
motivation: TSC FileSystem API changed to add tempDirectory accessor changes: add tempDirectory accessor in SwiftPM FileSystem implementations rdar://86644116
1 parent 41e9701 commit ebf7c43

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

Sources/Basics/VirtualFileSystem.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ public class VirtualFileSystem: FileSystem {
177177

178178
public var cachesDirectory: AbsolutePath? = nil
179179

180+
public var tempDirectory = AbsolutePath("/")
181+
180182
public func createSymbolicLink(_ path: AbsolutePath, pointingAt destination: AbsolutePath, relative: Bool) throws {
181183
throw Errors.readOnlyFileSystem
182184
}

Sources/Commands/SwiftTool.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,8 @@ private func getSharedSecurityDirectory(options: SwiftToolOptions, observability
10351035

10361036
do {
10371037
let sharedSecurityDirectory = try localFileSystem.getOrCreateSwiftPMSecurityDirectory()
1038-
// And make sure we can write files (locking the directory writes a lock file)
1039-
try localFileSystem.withLock(on: sharedSecurityDirectory, type: .exclusive) { }
1038+
// make sure we can write files
1039+
try withTemporaryFile(dir: sharedSecurityDirectory) { _ in }
10401040
return sharedSecurityDirectory
10411041
} catch {
10421042
observabilityScope.emit(warning: "Failed creating default security location, \(error)")
@@ -1054,7 +1054,10 @@ private func getSharedConfigurationDirectory(options: SwiftToolOptions, observab
10541054
}
10551055

10561056
do {
1057-
return try localFileSystem.getOrCreateSwiftPMConfigurationDirectory(observabilityScope: observabilityScope)
1057+
let sharedConfigurationDirector = try localFileSystem.getOrCreateSwiftPMConfigurationDirectory(observabilityScope: observabilityScope)
1058+
// make sure we can write files
1059+
try withTemporaryFile(dir: sharedConfigurationDirector) { _ in }
1060+
return sharedConfigurationDirector
10581061
} catch {
10591062
observabilityScope.emit(warning: "Failed creating default configuration location, \(error)")
10601063
return .none
@@ -1071,7 +1074,10 @@ private func getSharedCacheDirectory(options: SwiftToolOptions, observabilitySco
10711074
}
10721075

10731076
do {
1074-
return try localFileSystem.getOrCreateSwiftPMCacheDirectory()
1077+
let sharedCacheDirector = try localFileSystem.getOrCreateSwiftPMCacheDirectory()
1078+
// make sure we can write files
1079+
try withTemporaryFile(dir: sharedCacheDirector) { _ in }
1080+
return sharedCacheDirector
10751081
} catch {
10761082
observabilityScope.emit(warning: "Failed creating default cache location, \(error)")
10771083
return .none

Sources/SPMTestSupport/InMemoryGitRepository.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ public final class InMemoryGitRepository {
204204
}
205205

206206
extension InMemoryGitRepository: FileSystem {
207-
208207
public func exists(_ path: AbsolutePath, followSymlink: Bool) -> Bool {
209208
self.lock.withLock {
210209
self.head.fileSystem.exists(path, followSymlink: followSymlink)
@@ -251,6 +250,10 @@ extension InMemoryGitRepository: FileSystem {
251250
fatalError("Unsupported")
252251
}
253252

253+
public var tempDirectory: AbsolutePath {
254+
fatalError("Unsupported")
255+
}
256+
254257
public func getDirectoryContents(_ path: AbsolutePath) throws -> [String] {
255258
try self.lock.withLock {
256259
try self.head.fileSystem.getDirectoryContents(path)

Sources/SourceControl/GitRepository.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,10 @@ private class GitFileSystemView: FileSystem {
890890
fatalError("unsupported")
891891
}
892892

893+
public var tempDirectory: AbsolutePath {
894+
fatalError("unsupported")
895+
}
896+
893897
func createDirectory(_ path: AbsolutePath) throws {
894898
throw FileSystemError(.unsupported, path)
895899
}

Tests/BasicsTests/URLSessionHTTPClientTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,10 @@ class FailingFileSystem: FileSystem {
704704
fatalError("unexpected call")
705705
}
706706

707+
var tempDirectory: AbsolutePath {
708+
fatalError("unexpected call")
709+
}
710+
707711
func changeCurrentWorkingDirectory(to path: AbsolutePath) throws {
708712
fatalError("unexpected call")
709713
}

0 commit comments

Comments
 (0)