diff --git a/Sources/DropboxFileProvider.swift b/Sources/DropboxFileProvider.swift index b509310..5cc9ff7 100644 --- a/Sources/DropboxFileProvider.swift +++ b/Sources/DropboxFileProvider.swift @@ -179,7 +179,7 @@ extension DropboxFileProvider: FileProviderOperations { completionHandler?(error: error) return } - upload_simple(toPath, data: data, overwrite: true, operation: .Copy(source: localFile.absoluteString, destination: toPath), completionHandler: completionHandler) + upload_simple(toPath, data: data, overwrite: true, operation: .Copy(source: localFile.uw_absoluteString, destination: toPath), completionHandler: completionHandler) } public func copyPathToLocalFile(path: String, toLocalURL destURL: NSURL, completionHandler: SimpleCompletionHandler) { @@ -328,4 +328,4 @@ extension DropboxFileProvider: ExtendedFileProvider { } } -extension DropboxFileProvider: FileProvider {} \ No newline at end of file +extension DropboxFileProvider: FileProvider {} diff --git a/Sources/DropboxHelper.swift b/Sources/DropboxHelper.swift index b5b9926..e5013ed 100644 --- a/Sources/DropboxHelper.swift +++ b/Sources/DropboxHelper.swift @@ -23,14 +23,17 @@ public final class DropboxFileObject: FileObject { public let id: String? public let rev: String? + // codebeat:disable[ARITY] public init(name: String, path: String, size: Int64 = -1, serverTime: NSDate? = nil, modifiedDate: NSDate? = nil, fileType: FileType = .Regular, isHidden: Bool = false, isReadOnly: Bool = false, id: String? = nil, rev: String? = nil) { self.serverTime = serverTime self.id = id self.rev = rev super.init(absoluteURL: NSURL(string: path), name: name, path: path, size: size, createdDate: nil, modifiedDate: modifiedDate, fileType: fileType, isHidden: isHidden, isReadOnly: isReadOnly) } + // codebeat:enable[ARITY] } +// codebeat:disable[ARITY] internal extension DropboxFileProvider { func list(path: String, cursor: String? = nil, prevContents: [DropboxFileObject] = [], recursive: Bool = false, completionHandler: ((contents: [FileObject], cursor: String?, error: ErrorType?) -> Void)) { var requestDictionary = [String: AnyObject]() @@ -161,6 +164,7 @@ internal extension DropboxFileProvider { task.resume() } } +// codebeat:enable[ARITY] internal extension DropboxFileProvider { func mapToFileObject(jsonStr: String) -> DropboxFileObject? { diff --git a/Sources/LocalFileProvider.swift b/Sources/LocalFileProvider.swift index baaaa84..1e36170 100644 --- a/Sources/LocalFileProvider.swift +++ b/Sources/LocalFileProvider.swift @@ -10,11 +10,12 @@ import Foundation public final class LocalFileObject: FileObject { public let allocatedSize: Int64 - + // codebeat:disable[ARITY] public init(absoluteURL: NSURL, name: String, path: String, size: Int64 = -1, allocatedSize: Int64 = 0, createdDate: NSDate? = nil, modifiedDate: NSDate? = nil, fileType: FileType = .Regular, isHidden: Bool = false, isReadOnly: Bool = false) { self.allocatedSize = allocatedSize super.init(absoluteURL: absoluteURL, name: name, path: path, size: size, createdDate: createdDate, modifiedDate: modifiedDate, fileType: fileType, isHidden: isHidden, isReadOnly: isReadOnly) } + // codebeat:enable[ARITY] } public class LocalFileProvider: FileProvider, FileProviderMonitor { diff --git a/Sources/SMBTypes/SMB2Types.swift b/Sources/SMBTypes/SMB2Types.swift index 0cb115a..3724429 100644 --- a/Sources/SMBTypes/SMB2Types.swift +++ b/Sources/SMBTypes/SMB2Types.swift @@ -45,6 +45,7 @@ struct SMB2 { let sessionId: UInt64 let signature: (UInt64, UInt64) + // codebeat:disable[ARITY] init(command: Command, status: NTStatus = .SUCCESS, creditCharge: UInt16 = 0, creditRequestResponse: UInt16, flags: Flags = [], nextCommand: UInt32 = 0, messageId: UInt64, treeId: UInt32, sessionId: UInt64, signature: (UInt64, UInt64) = (0, 0)) { self.protocolID = self.dynamicType.protocolConst self.size = 64 @@ -76,6 +77,7 @@ struct SMB2 { self.sessionId = sessionId self.signature = signature } + // codebeat:enable[ARITY] } struct Flags: OptionSetType { diff --git a/Sources/SessionDelegate.swift b/Sources/SessionDelegate.swift index 2c945f8..642689d 100644 --- a/Sources/SessionDelegate.swift +++ b/Sources/SessionDelegate.swift @@ -22,6 +22,7 @@ class SessionDelegate: NSObject, NSURLSessionDataDelegate, NSURLSessionDownloadD self.credential = credential } + // codebeat:disable[ARITY] func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL) { self.finishDownloadHandler?(session: session, downloadTask: downloadTask, didFinishDownloadingToURL: location) return diff --git a/Sources/WebDAVFileProvider.swift b/Sources/WebDAVFileProvider.swift index 8dced65..f4a78a7 100644 --- a/Sources/WebDAVFileProvider.swift +++ b/Sources/WebDAVFileProvider.swift @@ -12,11 +12,13 @@ public final class WebDavFileObject: FileObject { public let contentType: String public let entryTag: String? + // codebeat:disable[ARITY] public init(absoluteURL: NSURL, name: String, path: String, size: Int64 = -1, contentType: String = "", createdDate: NSDate? = nil, modifiedDate: NSDate? = nil, fileType: FileType = .Regular, isHidden: Bool = false, isReadOnly: Bool = false, entryTag: String? = nil) { self.contentType = contentType self.entryTag = entryTag super.init(absoluteURL: absoluteURL, name: name, path: path, size: size, createdDate: createdDate, modifiedDate: modifiedDate, fileType: fileType, isHidden: isHidden, isReadOnly: isReadOnly) } + // codebeat:enable[ARITY] } // Because this class uses NSURLSession, it's necessary to disable App Transport Security @@ -409,49 +411,8 @@ internal extension WebDAVFileProvider { break } for responseNode in rootnode[responsetag].all ?? [] { - var hreftag = "href" - var statustag = "status" - var propstattag = "propstat" - for node in responseNode.children ?? [] { - if node.name.lowercaseString.hasSuffix("href") { - hreftag = node.name - } - if node.name.lowercaseString.hasSuffix("status") { - statustag = node.name - } - if node.name.lowercaseString.hasSuffix("propstat") { - propstattag = node.name - } - } - let href = responseNode[hreftag].value - if let href = href, hrefURL = NSURL(string: href) { - var status: Int? - let statusDesc = (responseNode[statustag].stringValue).componentsSeparatedByString(" ") - if statusDesc.count > 2 { - status = Int(statusDesc[1]) - } - var propDic = [String: String]() - let propStatNode = responseNode[propstattag] - for node in propStatNode.children ?? [] where node.name.lowercaseString.hasSuffix("status"){ - statustag = node.name - break - } - let statusDesc2 = (propStatNode[statustag].stringValue).componentsSeparatedByString(" ") - if statusDesc2.count > 2 { - status = Int(statusDesc2[1]) - } - var proptag = "prop" - for tnode in propStatNode.children ?? [] where tnode.name.lowercaseString.hasSuffix("prop") { - proptag = tnode.name - break - } - for propItemNode in propStatNode[proptag].children ?? [] { - propDic[propItemNode.name.componentsSeparatedByString(":").last!.lowercaseString] = propItemNode.value - if propItemNode.name.hasSuffix("resourcetype") && propItemNode.xmlString.containsString("collection") { - propDic["getcontenttype"] = "httpd/unix-directory" - } - } - result.append(DavResponse(href: hrefURL, hrefString: href, status: status, prop: propDic)) + if let davResponse = mapNodeToDavResponse(responseNode) { + result.append(davResponse) } } } catch _ { @@ -459,6 +420,54 @@ internal extension WebDAVFileProvider { return result } + private func mapNodeToDavResponse(node: AEXMLElement) -> DavResponse? { + var hreftag = "href" + var statustag = "status" + var propstattag = "propstat" + for node in node.children ?? [] { + if node.name.lowercaseString.hasSuffix("href") { + hreftag = node.name + } + if node.name.lowercaseString.hasSuffix("status") { + statustag = node.name + } + if node.name.lowercaseString.hasSuffix("propstat") { + propstattag = node.name + } + } + let href = node[hreftag].value + if let href = href, hrefURL = NSURL(string: href) { + var status: Int? + let statusDesc = (node[statustag].stringValue).componentsSeparatedByString(" ") + if statusDesc.count > 2 { + status = Int(statusDesc[1]) + } + var propDic = [String: String]() + let propStatNode = node[propstattag] + for node in propStatNode.children ?? [] where node.name.lowercaseString.hasSuffix("status"){ + statustag = node.name + break + } + let statusDesc2 = (propStatNode[statustag].stringValue).componentsSeparatedByString(" ") + if statusDesc2.count > 2 { + status = Int(statusDesc2[1]) + } + var proptag = "prop" + for tnode in propStatNode.children ?? [] where tnode.name.lowercaseString.hasSuffix("prop") { + proptag = tnode.name + break + } + for propItemNode in propStatNode[proptag].children ?? [] { + propDic[propItemNode.name.componentsSeparatedByString(":").last!.lowercaseString] = propItemNode.value + if propItemNode.name.hasSuffix("resourcetype") && propItemNode.xmlString.containsString("collection") { + propDic["getcontenttype"] = "httpd/unix-directory" + } + } + return DavResponse(href: hrefURL, hrefString: href, status: status, prop: propDic) + } + return nil + } + private func mapToFileObject(davResponse: DavResponse) -> WebDavFileObject { var href = davResponse.href if href.baseURL == nil {