Skip to content

Commit

Permalink
Only deleteItem if file exists at URL.
Browse files Browse the repository at this point in the history
Implemented here partly to ease merge with proposed changes in other pull requests.
  • Loading branch information
babbage committed Apr 7, 2018
1 parent 7424aee commit 43c639d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion FBSnapshotsViewer/Extensions/FileManager+Move.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import Foundation

extension FileManager {
func moveItem(at fromURL: URL, to toURL: URL) throws {
try self.removeItem(at: toURL)
try deleteItem(at: toURL)
try self.copyItem(at: fromURL, to: toURL)
}

func deleteItem(at url: URL) throws {
if fileExists(atPath: url.path) {
try self.removeItem(at: url)
}
}
}
6 changes: 3 additions & 3 deletions FBSnapshotsViewer/Managers/SnapshotTestResultSwapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ class SnapshotTestResultSwapper {
let failedImageURL = URL(fileURLWithPath: failedImagePath, isDirectory: false)

do {
try fileManager.removeItem(at: referenceImageURL)
try fileManager.removeItem(at: diffImageURL)
try fileManager.removeItem(at: failedImageURL)
try fileManager.deleteItem(at: referenceImageURL)
try fileManager.deleteItem(at: diffImageURL)
try fileManager.deleteItem(at: failedImageURL)
}
catch let error {
throw SnapshotTestResultSwapperError.canNotPerformFileManagerOperation(testResult: testResult, underlyingError: error)
Expand Down

0 comments on commit 43c639d

Please sign in to comment.