Skip to content

Commit

Permalink
Fixes #39 (FTP listing), Error domain determination
Browse files Browse the repository at this point in the history
  • Loading branch information
amosavian committed May 5, 2017
1 parent b13df0a commit f94719d
Show file tree
Hide file tree
Showing 5 changed files with 17 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.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.
Expand Down
4 changes: 2 additions & 2 deletions FileProvider.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Sources/FTPFileProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 7 additions & 4 deletions Sources/FTPHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/FileProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,8 @@ extension FileProviderBasic {
let domain: String
switch code {
case is URLError:
fallthrough
case is URLError.Code:
domain = NSURLErrorDomain
default:
domain = NSCocoaErrorDomain
Expand Down

0 comments on commit f94719d

Please sign in to comment.