@@ -21,11 +21,15 @@ import TSCBasic
21
21
extension FileSystem {
22
22
/// SwiftPM directory under user's home directory (~/.swiftpm)
23
23
public var dotSwiftPM : AbsolutePath {
24
- self . homeDirectory. appending ( component: " .swiftpm " )
24
+ get throws {
25
+ return try self . homeDirectory. appending ( component: " .swiftpm " )
26
+ }
25
27
}
26
28
27
29
fileprivate var idiomaticSwiftPMDirectory : AbsolutePath ? {
28
- return FileManager . default. urls ( for: . libraryDirectory, in: . userDomainMask) . first. flatMap { AbsolutePath ( $0. path) } ? . appending ( component: " org.swift.swiftpm " )
30
+ get throws {
31
+ return try FileManager . default. urls ( for: . libraryDirectory, in: . userDomainMask) . first. flatMap { try AbsolutePath ( validating: $0. path) } ? . appending ( component: " org.swift.swiftpm " )
32
+ }
29
33
}
30
34
}
31
35
@@ -39,33 +43,37 @@ extension FileSystem {
39
43
40
44
/// SwiftPM cache directory under user's caches directory (if exists)
41
45
public var swiftPMCacheDirectory : AbsolutePath {
42
- if let path = self . idiomaticUserCacheDirectory {
43
- return path. appending ( component: " org.swift.swiftpm " )
44
- } else {
45
- return self . dotSwiftPMCachesDirectory
46
+ get throws {
47
+ if let path = self . idiomaticUserCacheDirectory {
48
+ return path. appending ( component: " org.swift.swiftpm " )
49
+ } else {
50
+ return try self . dotSwiftPMCachesDirectory
51
+ }
46
52
}
47
53
}
48
54
49
55
fileprivate var dotSwiftPMCachesDirectory : AbsolutePath {
50
- return self . dotSwiftPM. appending ( component: " cache " )
56
+ get throws {
57
+ return try self . dotSwiftPM. appending ( component: " cache " )
58
+ }
51
59
}
52
60
}
53
61
54
62
extension FileSystem {
55
63
public func getOrCreateSwiftPMCacheDirectory( ) throws -> AbsolutePath {
56
- let idiomaticCacheDirectory = self . swiftPMCacheDirectory
64
+ let idiomaticCacheDirectory = try self . swiftPMCacheDirectory
57
65
// Create idiomatic if necessary
58
66
if !self . exists ( idiomaticCacheDirectory) {
59
67
try self . createDirectory ( idiomaticCacheDirectory, recursive: true )
60
68
}
61
69
// Create ~/.swiftpm if necessary
62
- if !self . exists ( self . dotSwiftPM) {
70
+ if !self . exists ( try self . dotSwiftPM) {
63
71
try self . createDirectory ( self . dotSwiftPM, recursive: true )
64
72
}
65
73
// Create ~/.swiftpm/cache symlink if necessary
66
74
// locking ~/.swiftpm to protect from concurrent access
67
75
try self . withLock ( on: self . dotSwiftPM, type: . exclusive) {
68
- if !self . exists ( self . dotSwiftPMCachesDirectory, followSymlink: false ) {
76
+ if !self . exists ( try self . dotSwiftPMCachesDirectory, followSymlink: false ) {
69
77
try self . createSymbolicLink ( dotSwiftPMCachesDirectory, pointingAt: idiomaticCacheDirectory, relative: false )
70
78
}
71
79
}
@@ -78,21 +86,25 @@ extension FileSystem {
78
86
extension FileSystem {
79
87
/// SwiftPM config directory under user's config directory (if exists)
80
88
public var swiftPMConfigurationDirectory : AbsolutePath {
81
- if let path = self . idiomaticSwiftPMDirectory {
82
- return path. appending ( component: " configuration " )
83
- } else {
84
- return self . dotSwiftPMConfigurationDirectory
89
+ get throws {
90
+ if let path = try self . idiomaticSwiftPMDirectory {
91
+ return path. appending ( component: " configuration " )
92
+ } else {
93
+ return try self . dotSwiftPMConfigurationDirectory
94
+ }
85
95
}
86
96
}
87
97
88
98
fileprivate var dotSwiftPMConfigurationDirectory : AbsolutePath {
89
- return self . dotSwiftPM. appending ( component: " configuration " )
99
+ get throws {
100
+ return try self . dotSwiftPM. appending ( component: " configuration " )
101
+ }
90
102
}
91
103
}
92
104
93
105
extension FileSystem {
94
106
public func getOrCreateSwiftPMConfigurationDirectory( warningHandler: @escaping ( String ) -> Void ) throws -> AbsolutePath {
95
- let idiomaticConfigurationDirectory = self . swiftPMConfigurationDirectory
107
+ let idiomaticConfigurationDirectory = try self . swiftPMConfigurationDirectory
96
108
97
109
// temporary 5.6, remove on next version: transition from previous configuration location
98
110
if !self . exists ( idiomaticConfigurationDirectory) {
@@ -116,7 +128,7 @@ extension FileSystem {
116
128
}
117
129
118
130
// in the case where ~/.swiftpm/configuration is not the idiomatic location (eg on macOS where its /Users/<user>/Library/org.swift.swiftpm/configuration)
119
- if idiomaticConfigurationDirectory != self . dotSwiftPMConfigurationDirectory {
131
+ if try idiomaticConfigurationDirectory != self . dotSwiftPMConfigurationDirectory {
120
132
// copy the configuration files from old location (eg /Users/<user>/Library/org.swift.swiftpm) to new one (eg /Users/<user>/Library/org.swift.swiftpm/configuration)
121
133
// but leave them there for backwards compatibility (eg older xcode)
122
134
let oldConfigDirectory = idiomaticConfigurationDirectory. parentDirectory
@@ -130,7 +142,7 @@ extension FileSystem {
130
142
} else {
131
143
// copy the configuration files from old location (~/.swiftpm/config) to new one (~/.swiftpm/configuration)
132
144
// but leave them there for backwards compatibility (eg older toolchain)
133
- let oldConfigDirectory = self . dotSwiftPM. appending ( component: " config " )
145
+ let oldConfigDirectory = try self . dotSwiftPM. appending ( component: " config " )
134
146
if self . exists ( oldConfigDirectory, followSymlink: false ) && self . isDirectory ( oldConfigDirectory) {
135
147
let configurationFiles = try self . getDirectoryContents ( oldConfigDirectory)
136
148
. map { oldConfigDirectory. appending ( component: $0) }
@@ -145,13 +157,13 @@ extension FileSystem {
145
157
try self . createDirectory ( idiomaticConfigurationDirectory, recursive: true )
146
158
}
147
159
// Create ~/.swiftpm if necessary
148
- if !self . exists ( self . dotSwiftPM) {
160
+ if !self . exists ( try self . dotSwiftPM) {
149
161
try self . createDirectory ( self . dotSwiftPM, recursive: true )
150
162
}
151
163
// Create ~/.swiftpm/configuration symlink if necessary
152
164
// locking ~/.swiftpm to protect from concurrent access
153
165
try self . withLock ( on: self . dotSwiftPM, type: . exclusive) {
154
- if !self . exists ( self . dotSwiftPMConfigurationDirectory, followSymlink: false ) {
166
+ if !self . exists ( try self . dotSwiftPMConfigurationDirectory, followSymlink: false ) {
155
167
try self . createSymbolicLink ( dotSwiftPMConfigurationDirectory, pointingAt: idiomaticConfigurationDirectory, relative: false )
156
168
}
157
169
}
@@ -165,26 +177,30 @@ extension FileSystem {
165
177
extension FileSystem {
166
178
/// SwiftPM security directory under user's security directory (if exists)
167
179
public var swiftPMSecurityDirectory : AbsolutePath {
168
- if let path = self . idiomaticSwiftPMDirectory {
169
- return path. appending ( component: " security " )
170
- } else {
171
- return self . dotSwiftPMSecurityDirectory
180
+ get throws {
181
+ if let path = try self . idiomaticSwiftPMDirectory {
182
+ return path. appending ( component: " security " )
183
+ } else {
184
+ return try self . dotSwiftPMSecurityDirectory
185
+ }
172
186
}
173
187
}
174
188
175
189
fileprivate var dotSwiftPMSecurityDirectory : AbsolutePath {
176
- return self . dotSwiftPM. appending ( component: " security " )
190
+ get throws {
191
+ return try self . dotSwiftPM. appending ( component: " security " )
192
+ }
177
193
}
178
194
}
179
195
180
196
extension FileSystem {
181
197
public func getOrCreateSwiftPMSecurityDirectory( ) throws -> AbsolutePath {
182
- let idiomaticSecurityDirectory = self . swiftPMSecurityDirectory
198
+ let idiomaticSecurityDirectory = try self . swiftPMSecurityDirectory
183
199
184
200
// temporary 5.6, remove on next version: transition from ~/.swiftpm/security to idiomatic location + symbolic link
185
- if idiomaticSecurityDirectory != self . dotSwiftPMSecurityDirectory &&
186
- self . exists ( self . dotSwiftPMSecurityDirectory) &&
187
- self . isDirectory ( self . dotSwiftPMSecurityDirectory) {
201
+ if try idiomaticSecurityDirectory != self . dotSwiftPMSecurityDirectory &&
202
+ self . exists ( try self . dotSwiftPMSecurityDirectory) &&
203
+ self . isDirectory ( try self . dotSwiftPMSecurityDirectory) {
188
204
try self . removeFileTree ( self . dotSwiftPMSecurityDirectory)
189
205
}
190
206
// ~temporary 5.6 migration
@@ -194,13 +210,13 @@ extension FileSystem {
194
210
try self . createDirectory ( idiomaticSecurityDirectory, recursive: true )
195
211
}
196
212
// Create ~/.swiftpm if necessary
197
- if !self . exists ( self . dotSwiftPM) {
213
+ if !self . exists ( try self . dotSwiftPM) {
198
214
try self . createDirectory ( self . dotSwiftPM, recursive: true )
199
215
}
200
216
// Create ~/.swiftpm/security symlink if necessary
201
217
// locking ~/.swiftpm to protect from concurrent access
202
218
try self . withLock ( on: self . dotSwiftPM, type: . exclusive) {
203
- if !self . exists ( self . dotSwiftPMSecurityDirectory, followSymlink: false ) {
219
+ if !self . exists ( try self . dotSwiftPMSecurityDirectory, followSymlink: false ) {
204
220
try self . createSymbolicLink ( dotSwiftPMSecurityDirectory, pointingAt: idiomaticSecurityDirectory, relative: false )
205
221
}
206
222
}
0 commit comments