Skip to content

Commit

Permalink
Fixed relativePath(of:) crash
Browse files Browse the repository at this point in the history
  • Loading branch information
amosavian committed Mar 18, 2017
1 parent 079f8f4 commit 528d5ee
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion FileProvider.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions FileProvider.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions Sources/FileProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
2 changes: 1 addition & 1 deletion Sources/LocalFileProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 528d5ee

Please sign in to comment.