diff --git a/Sources/CodableDatastore/Persistence/Disk Persistence/DiskPersistence.swift b/Sources/CodableDatastore/Persistence/Disk Persistence/DiskPersistence.swift index b1546c2..97e24a2 100644 --- a/Sources/CodableDatastore/Persistence/Disk Persistence/DiskPersistence.swift +++ b/Sources/CodableDatastore/Persistence/Disk Persistence/DiskPersistence.swift @@ -149,7 +149,7 @@ extension DiskPersistence { cachedStoreInfo = storeInfo return storeInfo - } catch URLError.fileDoesNotExist, CocoaError.fileNoSuchFile, CocoaError.fileReadNoSuchFile, POSIXError.ENOENT { + } catch FileNotFoundError() { return nil } catch { throw error diff --git a/Sources/CodableDatastore/Persistence/Disk Persistence/FileNotFoundError.swift b/Sources/CodableDatastore/Persistence/Disk Persistence/FileNotFoundError.swift new file mode 100644 index 0000000..a7cc139 --- /dev/null +++ b/Sources/CodableDatastore/Persistence/Disk Persistence/FileNotFoundError.swift @@ -0,0 +1,26 @@ +// +// FileNotFoundError.swift +// https://github.com/mochidev/CodableDatastore +// +// Created by Dimitri Bouniol on 2026-08-30. +// Copyright © 2023-26 Mochi Development, Inc. All rights reserved. +// mochidev-codable-datastore: 8A3D87799CB24B2BA7A7661369B88325 +// + +import Foundation + +struct FileNotFoundError: Error { + static func ~= (lhs: FileNotFoundError, rhs: any Error) -> Bool { + (rhs as any FileError).isFileNotFound == true + } +} + +protocol FileError { + var isFileNotFound: Bool { get } +} + +extension NSError: FileError { + var isFileNotFound: Bool { + URLError.fileDoesNotExist ~= self || CocoaError.fileReadNoSuchFile ~= self || CocoaError.fileNoSuchFile ~= self || POSIXError.ENOENT ~= self + } +} diff --git a/Sources/CodableDatastore/Persistence/Disk Persistence/Snapshot/Snapshot.swift b/Sources/CodableDatastore/Persistence/Disk Persistence/Snapshot/Snapshot.swift index bdd0839..eaaa3d3 100644 --- a/Sources/CodableDatastore/Persistence/Disk Persistence/Snapshot/Snapshot.swift +++ b/Sources/CodableDatastore/Persistence/Disk Persistence/Snapshot/Snapshot.swift @@ -119,7 +119,7 @@ extension Snapshot { cachedManifest = manifest return manifest - } catch URLError.fileDoesNotExist, CocoaError.fileNoSuchFile, CocoaError.fileReadNoSuchFile, POSIXError.ENOENT { + } catch FileNotFoundError() { return SnapshotManifest(id: id, modificationDate: Date()) } catch { throw error