From bd277012b6d867fb526a8e181f01ded8879aa9ee Mon Sep 17 00:00:00 2001 From: Duncan Babbage Date: Sat, 7 Apr 2018 21:21:53 +1200 Subject: [PATCH] Only deleteItem if file exists at path. Implemented here partly to ease merge with proposed changes in other pull requests. --- FBSnapshotsViewer/Extensions/FileManager+Move.swift | 6 ++++-- FBSnapshotsViewer/Managers/SnapshotTestResultSwapper.swift | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/FBSnapshotsViewer/Extensions/FileManager+Move.swift b/FBSnapshotsViewer/Extensions/FileManager+Move.swift index 3a29620..478f8f0 100644 --- a/FBSnapshotsViewer/Extensions/FileManager+Move.swift +++ b/FBSnapshotsViewer/Extensions/FileManager+Move.swift @@ -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) + } } } diff --git a/FBSnapshotsViewer/Managers/SnapshotTestResultSwapper.swift b/FBSnapshotsViewer/Managers/SnapshotTestResultSwapper.swift index 253af14..5e2bb91 100644 --- a/FBSnapshotsViewer/Managers/SnapshotTestResultSwapper.swift +++ b/FBSnapshotsViewer/Managers/SnapshotTestResultSwapper.swift @@ -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)