From 528d5eebc38c67d40147c881d5d284827f84c129 Mon Sep 17 00:00:00 2001 From: Amir Abbas Date: Sat, 18 Mar 2017 15:58:44 +0330 Subject: [PATCH] Fixed relativePath(of:) crash --- FileProvider.podspec | 2 +- FileProvider.xcodeproj/project.pbxproj | 4 ++-- Sources/FileProvider.swift | 8 +++++--- Sources/LocalFileProvider.swift | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/FileProvider.podspec b/FileProvider.podspec index e46a4d9..086553d 100644 --- a/FileProvider.podspec +++ b/FileProvider.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "FileProvider" - s.version = "0.14.3" + s.version = "0.14.4" s.summary = "FileManager replacement for Local and Remote (WebDAV/Dropbox/OneDrive/SMB2) files on iOS and macOS." # This description is used to generate tags and improve search results. diff --git a/FileProvider.xcodeproj/project.pbxproj b/FileProvider.xcodeproj/project.pbxproj index 728921c..bb4c2df 100644 --- a/FileProvider.xcodeproj/project.pbxproj +++ b/FileProvider.xcodeproj/project.pbxproj @@ -605,7 +605,7 @@ 799396601D48B7BF00086753 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - BUNDLE_VERSION_STRING = 0.14.3; + BUNDLE_VERSION_STRING = 0.14.4; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -635,7 +635,7 @@ 799396611D48B7BF00086753 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - BUNDLE_VERSION_STRING = 0.14.3; + BUNDLE_VERSION_STRING = 0.14.4; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; diff --git a/Sources/FileProvider.swift b/Sources/FileProvider.swift index 73e8b03..a505f81 100644 --- a/Sources/FileProvider.swift +++ b/Sources/FileProvider.swift @@ -637,15 +637,17 @@ extension FileProviderBasic { /// - Returns: A `String` contains relative path of url against base url. public func relativePathOf(url: URL) -> String { // check if url derieved from current base url - if !url.relativePath.isEmpty, url.baseURL == self.baseURL { - return url.relativePath.removingPercentEncoding! + let relativePath = url.relativePath + if !relativePath.isEmpty, url.baseURL == self.baseURL { + return relativePath.removingPercentEncoding ?? relativePath } // resolve url string against baseurl guard let baseURL = self.baseURL?.standardizedFileURL else { return url.absoluteString } let standardPath = url.absoluteString.replacingOccurrences(of: "file:///private/var/", with: "file:///var/", options: .anchored) let standardBase = baseURL.absoluteString.replacingOccurrences(of: "file:///private/var/", with: "file:///var/", options: .anchored) - return standardPath.replacingOccurrences(of: standardBase, with: "/").removingPercentEncoding! + let standardRelativePath = standardPath.replacingOccurrences(of: standardBase, with: "/") + return standardRelativePath.removingPercentEncoding ?? standardRelativePath } internal func correctPath(_ path: String?) -> String? { diff --git a/Sources/LocalFileProvider.swift b/Sources/LocalFileProvider.swift index c92c053..7fa7595 100644 --- a/Sources/LocalFileProvider.swift +++ b/Sources/LocalFileProvider.swift @@ -480,7 +480,7 @@ open class LocalFileProvider: FileProvider, FileProviderMonitor, FileProvideUndo open func registerNotifcation(path: String, eventHandler: @escaping (() -> Void)) { self.unregisterNotifcation(path: path) let dirurl = self.url(of: path) - let isdir = (try? dirurl.resourceValues(forKeys: [.isDirectoryKey]).isDirectory ?? false) ?? false + let isdir = (try? dirurl.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false if !isdir { return }