Skip to content

Commit

Permalink
Only deleteItem if file exists at path.
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 5b43c65 commit bd27701
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions FBSnapshotsViewer/Extensions/FileManager+Move.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import Foundation

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

func deleteItem(at url: URL) throws {
try self.removeItem(at: url)
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 @@ -83,9 +83,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 bd27701

Please sign in to comment.