From f94719deb0975cf2312774f3501a64c585ff9bed Mon Sep 17 00:00:00 2001 From: Amir Abbas Date: Fri, 5 May 2017 13:02:07 +0430 Subject: [PATCH] Fixes #39 (FTP listing), Error domain determination --- FileProvider.podspec | 2 +- FileProvider.xcodeproj/project.pbxproj | 4 ++-- Sources/FTPFileProvider.swift | 5 +++++ Sources/FTPHelper.swift | 11 +++++++---- Sources/FileProvider.swift | 2 ++ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/FileProvider.podspec b/FileProvider.podspec index a279941..6148aa1 100644 --- a/FileProvider.podspec +++ b/FileProvider.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "FileProvider" - s.version = "0.16.1" + s.version = "0.16.2" s.summary = "FileManager replacement for Local and Remote (WebDAV/FTP/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 9103be8..0c5db16 100644 --- a/FileProvider.xcodeproj/project.pbxproj +++ b/FileProvider.xcodeproj/project.pbxproj @@ -621,7 +621,7 @@ 799396601D48B7BF00086753 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - BUNDLE_VERSION_STRING = 0.16.1; + BUNDLE_VERSION_STRING = 0.16.2; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -652,7 +652,7 @@ 799396611D48B7BF00086753 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - BUNDLE_VERSION_STRING = 0.16.1; + BUNDLE_VERSION_STRING = 0.16.2; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; diff --git a/Sources/FTPFileProvider.swift b/Sources/FTPFileProvider.swift index b835c8c..326165a 100644 --- a/Sources/FTPFileProvider.swift +++ b/Sources/FTPFileProvider.swift @@ -173,6 +173,11 @@ open class FTPFileProvider: FileProviderBasicRemote { self.ftpQuit(task) } if let error = error { + if ((error as NSError).domain == URLError.errorDomain && (error as NSError).code == URLError.unsupportedURL.rawValue) { + self.contentsOfDirectory(path: path, rfc3659enabled: false, completionHandler: completionHandler) + return + } + self.dispatch_queue.async { completionHandler([], error) } diff --git a/Sources/FTPHelper.swift b/Sources/FTPHelper.swift index 63a31c6..c85f62b 100644 --- a/Sources/FTPHelper.swift +++ b/Sources/FTPHelper.swift @@ -297,7 +297,7 @@ internal extension FTPFileProvider { var success = false let command = useMLST ? "MLSD \(path)" : "LIST \(path)" - self.execute(command: command, on: task, minLength: 70, afterSend: { error in + self.execute(command: command, on: task, minLength: 20, afterSend: { error in // starting passive task let timeout = self.session.configuration.timeoutIntervalForRequest @@ -308,7 +308,7 @@ internal extension FTPFileProvider { while !eof { let group = DispatchGroup() group.enter() - dataTask.readData(ofMinLength: 0, maxLength: 65535, timeout: timeout, completionHandler: { (data, seof, serror) in + dataTask.readData(ofMinLength: 1, maxLength: 65535, timeout: timeout, completionHandler: { (data, seof, serror) in if let data = data { finalData.append(data) } @@ -319,7 +319,9 @@ internal extension FTPFileProvider { let waitResult = group.wait(timeout: .now() + timeout) if let error = error { - completionHandler([], error) + if !((error as NSError).domain == URLError.errorDomain && (error as NSError).code == URLError.cancelled.rawValue) { + completionHandler([], error) + } return } @@ -351,7 +353,8 @@ internal extension FTPFileProvider { } if response.hasPrefix("50") && useMLST { - self.ftpList(task, of: path, useMLST: false, completionHandler: completionHandler) + dataTask.cancel() + completionHandler([], self.throwError(path, code: URLError.unsupportedURL)) return } diff --git a/Sources/FileProvider.swift b/Sources/FileProvider.swift index 887854d..3d54c25 100644 --- a/Sources/FileProvider.swift +++ b/Sources/FileProvider.swift @@ -730,6 +730,8 @@ extension FileProviderBasic { let domain: String switch code { case is URLError: + fallthrough + case is URLError.Code: domain = NSURLErrorDomain default: domain = NSCocoaErrorDomain