@@ -69,14 +69,10 @@ func generateDocs(module: String) throws {
69
69
print ( " 🗂️ Using DocC catalog \( doccCatalogUrl. lastPathComponent) " )
70
70
71
71
print ( " 📐 Copying theme " )
72
- do {
73
- try FileManager . default. copyItemIfExistsWithoutOverwrite (
74
- at: URL . currentDirectory ( ) . appending ( component: " theme-settings.json " ) ,
75
- to: doccCatalogUrl. appending ( component: " theme-settings.json " )
76
- )
77
- } catch CocoaError . fileReadNoSuchFile , CocoaError. fileWriteFileExists {
78
- // ignore
79
- }
72
+ try FileManager . default. copyItemIfExistsWithoutOverwrite (
73
+ at: URL . currentDirectory ( ) . appending ( component: " theme-settings.json " ) ,
74
+ to: doccCatalogUrl. appending ( component: " theme-settings.json " )
75
+ )
80
76
81
77
print ( " 📝 Generating docs " )
82
78
try shell ( [
@@ -125,22 +121,35 @@ extension FileManager {
125
121
func removeItemIfExists( at url: URL ) throws {
126
122
do {
127
123
try self . removeItem ( at: url)
128
- } catch let error as NSError where error. domain == CocoaError . errorDomain && error . code == CocoaError . fileNoSuchFile. rawValue {
124
+ } catch let error as NSError where error. isCocoaError ( . fileNoSuchFile) {
129
125
// ignore
130
126
}
131
127
}
132
128
133
129
func copyItemIfExistsWithoutOverwrite( at src: URL , to dst: URL ) throws {
134
130
do {
131
+ // https://github.com/apple/swift-corelibs-foundation/pull/4808
132
+ #if !canImport(Darwin)
133
+ do {
134
+ _ = try dst. checkResourceIsReachable ( )
135
+ throw NSError ( domain: CocoaError . errorDomain, code: CocoaError . fileWriteFileExists. rawValue)
136
+ } catch let error as NSError where error. isCocoaError ( . fileReadNoSuchFile) { }
137
+ #endif
135
138
try self . copyItem ( at: src, to: dst)
136
- } catch let error as NSError where error. domain == CocoaError . errorDomain && error . code == CocoaError . fileReadNoSuchFile. rawValue {
139
+ } catch let error as NSError where error. isCocoaError ( . fileReadNoSuchFile) {
137
140
// ignore
138
- } catch let error as NSError where error. domain == CocoaError . errorDomain && error . code == CocoaError . fileWriteFileExists. rawValue {
141
+ } catch let error as NSError where error. isCocoaError ( . fileWriteFileExists) {
139
142
// ignore
140
143
}
141
144
}
142
145
}
143
146
147
+ extension NSError {
148
+ func isCocoaError( _ code: CocoaError . Code ) -> Bool {
149
+ self . domain == CocoaError . errorDomain && self . code == code. rawValue
150
+ }
151
+ }
152
+
144
153
#if !canImport(Darwin)
145
154
extension URL {
146
155
public enum DirectoryHint : Equatable { case isDirectory, notDirectory, inferFromPath }
0 commit comments