diff --git a/FileProvider.podspec b/FileProvider.podspec index 069acb5..b8344a8 100644 --- a/FileProvider.podspec +++ b/FileProvider.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "FileProvider" - s.version = "0.11.3" + s.version = "0.11.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 59a0710..a0c56c8 100644 --- a/FileProvider.xcodeproj/project.pbxproj +++ b/FileProvider.xcodeproj/project.pbxproj @@ -603,7 +603,7 @@ 799396601D48B7BF00086753 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - BUNDLE_VERSION_STRING = 0.11.3; + BUNDLE_VERSION_STRING = 0.11.4; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -633,7 +633,7 @@ 799396611D48B7BF00086753 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - BUNDLE_VERSION_STRING = 0.11.3; + BUNDLE_VERSION_STRING = 0.11.4; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; diff --git a/Sources/LocalHelper.swift b/Sources/LocalHelper.swift index 691cd8a..e6fb140 100644 --- a/Sources/LocalHelper.swift +++ b/Sources/LocalHelper.swift @@ -14,27 +14,33 @@ public final class LocalFileObject: FileObject { } public convenience init? (fileWithPath path: String, relativeTo relativeURL: URL?) { - let fileURL: URL - var rpath = path.replacingOccurrences(of: relativeURL?.absoluteString ?? "", with: "") + var fileURL: URL? + var rpath = path.replacingOccurrences(of: relativeURL?.absoluteString ?? "", with: "", options: .anchored) if path.hasPrefix("/") { rpath.remove(at: rpath.startIndex) } if rpath.isEmpty { - fileURL = relativeURL ?? URL(fileURLWithPath: path) + fileURL = relativeURL } else { if #available(iOS 9.0, macOS 10.11, tvOS 9.0, *) { fileURL = URL(fileURLWithPath: rpath, relativeTo: relativeURL) } else { - fileURL = relativeURL?.appendingPathComponent(path) ?? URL(fileURLWithPath: path) + fileURL = URL(string: rpath, relativeTo: relativeURL) } } - self.init(fileWithURL: fileURL) + if let fileURL = fileURL { + self.init(fileWithURL: fileURL) + } else { + return nil + } } public convenience init?(fileWithURL fileURL: URL) { do { let values = try fileURL.resourceValues(forKeys: [.nameKey, .fileSizeKey, .fileAllocatedSizeKey, .creationDateKey, .contentModificationDateKey, .fileResourceTypeKey, .isHiddenKey, .isWritableKey, .typeIdentifierKey, .generationIdentifierKey]) - self.init(url: fileURL, name: values.name ?? fileURL.lastPathComponent, path: fileURL.relativePath) + let path = fileURL.relativePath.hasPrefix("/") ? fileURL.relativePath : "/" + fileURL.relativePath + + self.init(url: fileURL, name: values.name ?? fileURL.lastPathComponent, path: path) for (key, value) in values.allValues { self.allValues[key.rawValue] = value } diff --git a/Sources/WebDAVFileProvider.swift b/Sources/WebDAVFileProvider.swift index 7855594..87dee93 100644 --- a/Sources/WebDAVFileProvider.swift +++ b/Sources/WebDAVFileProvider.swift @@ -82,7 +82,7 @@ open class WebDAVFileProvider: FileProviderBasicRemote { var fileObjects = [WebDavFileObject]() if let data = data { let xresponse = DavResponse.parse(xmlResponse: data, baseURL: self.baseURL) - for attr in xresponse { + for attr in xresponse where attr.href != url { if attr.href.path == url.path { continue } @@ -480,10 +480,9 @@ struct DavResponse { guard let hrefString = node[hreftag].value else { return nil } // trying to figure out relative path out of href - let hrefURL: URL? - let newhrefString = URL(string: removeSlash(hrefString), relativeTo: baseURL)?.absoluteString ?? hrefString - let relativePath = newhrefString.replacingOccurrences(of: baseURL?.absoluteString ?? "", with: "", options: .anchored, range: nil) - hrefURL = URL(string: removeSlash(relativePath), relativeTo: baseURL) ?? baseURL + let hrefAbsolute = URL(string: hrefString, relativeTo: baseURL)?.absoluteString ?? hrefString + let relativePath = hrefAbsolute.replacingOccurrences(of: baseURL?.absoluteString ?? "", with: "", options: .anchored, range: nil) + let hrefURL = URL(string: removeSlash(relativePath), relativeTo: baseURL) ?? baseURL guard let href = hrefURL?.standardized else { return nil } @@ -548,7 +547,9 @@ public final class WebDavFileObject: FileObject { internal init(_ davResponse: DavResponse) { let href = davResponse.href let name = davResponse.prop["displayname"] ?? (davResponse.hrefString.removingPercentEncoding! as NSString).lastPathComponent - super.init(url: href, name: name, path: href.relativePath) + let relativePath = href.relativePath + let path = relativePath.hasPrefix("/") ? relativePath : ("/" + relativePath) + super.init(url: href, name: name, path: path) self.size = Int64(davResponse.prop["getcontentlength"] ?? "-1") ?? NSURLSessionTransferSizeUnknown self.creationDate = resolve(dateString: davResponse.prop["creationdate"] ?? "") self.modifiedDate = resolve(dateString: davResponse.prop["getlastmodified"] ?? "")