File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -346,8 +346,8 @@ extension Downloader: URLSessionDownloadDelegate {
346346}
347347
348348extension FileManager {
349- func moveDownloadedFile( from srcURL: URL , to dstURL: URL ) throws {
350- if fileExists ( atPath: dstURL. path ( percentEncoded: false ) ) {
349+ func moveDownloadedFile( from srcURL: URL , to dstURL: URL , percentEncoded : Bool = false ) throws {
350+ if fileExists ( atPath: dstURL. path ( percentEncoded: percentEncoded ) ) {
351351 try removeItem ( at: dstURL)
352352 }
353353
Original file line number Diff line number Diff line change @@ -165,4 +165,28 @@ final class DownloaderTests: XCTestCase {
165165 throw error
166166 }
167167 }
168+
169+ func testMoveDownloadedFilePercentEncodedFlag( ) throws {
170+ let appSupport = tempDir. appendingPathComponent ( " Application Support " )
171+ let destination = appSupport. appendingPathComponent ( " config.json " )
172+ let source1 = tempDir. appendingPathComponent ( " v1.incomplete " )
173+ let source2 = tempDir. appendingPathComponent ( " v2.incomplete " )
174+
175+ try FileManager . default. createDirectory ( at: appSupport, withIntermediateDirectories: true )
176+ try " existing " . write ( to: destination, atomically: true , encoding: . utf8)
177+ try " v1 " . write ( to: source1, atomically: true , encoding: . utf8)
178+ try " v2 " . write ( to: source2, atomically: true , encoding: . utf8)
179+
180+ XCTAssertThrowsError (
181+ try FileManager . default. moveDownloadedFile ( from: source1, to: destination, percentEncoded: true )
182+ ) { error in
183+ XCTAssertEqual ( ( error as NSError ) . code, 516 )
184+ }
185+ XCTAssertEqual ( try String ( contentsOf: destination) , " existing " )
186+
187+ XCTAssertNoThrow (
188+ try FileManager . default. moveDownloadedFile ( from: source2, to: destination, percentEncoded: false )
189+ )
190+ XCTAssertEqual ( try String ( contentsOf: destination) , " v2 " )
191+ }
168192}
You can’t perform that action at this time.
0 commit comments