Skip to content

Commit 47ca971

Browse files
committed
isReachable returns error (#87), Updating version
1 parent 0466f71 commit 47ca971

10 files changed

+42
-21
lines changed

FilesProvider.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "FilesProvider"
19-
s.version = "0.22.0"
19+
s.version = "0.23.0"
2020
s.summary = "FileManager replacement for Local and Remote (WebDAV/FTP/Dropbox/OneDrive/SMB2) files on iOS and macOS."
2121

2222
# This description is used to generate tags and improve search results.

FilesProvider.xcodeproj/project.pbxproj

+2-6
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@
7272
799396B91D48C02300086753 /* SMBFileProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 799396981D48C02300086753 /* SMBFileProvider.swift */; };
7373
799396BA1D48C02300086753 /* SMBFileProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 799396981D48C02300086753 /* SMBFileProvider.swift */; };
7474
799396BB1D48C02300086753 /* SMBFileProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 799396981D48C02300086753 /* SMBFileProvider.swift */; };
75-
799396BC1D48C02300086753 /* CIFSTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7993969A1D48C02300086753 /* CIFSTypes.swift */; };
76-
799396BD1D48C02300086753 /* CIFSTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7993969A1D48C02300086753 /* CIFSTypes.swift */; };
77-
799396BE1D48C02300086753 /* CIFSTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7993969A1D48C02300086753 /* CIFSTypes.swift */; };
7875
799396BF1D48C02300086753 /* SMB2DataTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7993969B1D48C02300086753 /* SMB2DataTypes.swift */; };
7976
799396C01D48C02300086753 /* SMB2DataTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7993969B1D48C02300086753 /* SMB2DataTypes.swift */; };
8077
799396C11D48C02300086753 /* SMB2DataTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7993969B1D48C02300086753 /* SMB2DataTypes.swift */; };
@@ -593,7 +590,6 @@
593590
799396B91D48C02300086753 /* SMBFileProvider.swift in Sources */,
594591
794C220E1D591A4B00EC49B8 /* SMB2QueryTypes.swift in Sources */,
595592
794C21FE1D58912A00EC49B8 /* DropboxHelper.swift in Sources */,
596-
799396BC1D48C02300086753 /* CIFSTypes.swift in Sources */,
597593
794C220A1D5893F800EC49B8 /* SMB2Notification.swift in Sources */,
598594
799396D11D48C02300086753 /* SMB2SetInfo.swift in Sources */,
599595
7924B1961D89DAE000589DB7 /* Document.swift in Sources */,
@@ -638,7 +634,6 @@
638634
799396BA1D48C02300086753 /* SMBFileProvider.swift in Sources */,
639635
794C220F1D591A4B00EC49B8 /* SMB2QueryTypes.swift in Sources */,
640636
794C21FF1D58912A00EC49B8 /* DropboxHelper.swift in Sources */,
641-
799396BD1D48C02300086753 /* CIFSTypes.swift in Sources */,
642637
794C220B1D5893F800EC49B8 /* SMB2Notification.swift in Sources */,
643638
799396D21D48C02300086753 /* SMB2SetInfo.swift in Sources */,
644639
7924B1971D89DAE000589DB7 /* Document.swift in Sources */,
@@ -683,7 +678,6 @@
683678
799396BB1D48C02300086753 /* SMBFileProvider.swift in Sources */,
684679
794C22101D591A4B00EC49B8 /* SMB2QueryTypes.swift in Sources */,
685680
794C22001D58912A00EC49B8 /* DropboxHelper.swift in Sources */,
686-
799396BE1D48C02300086753 /* CIFSTypes.swift in Sources */,
687681
794C220C1D5893F800EC49B8 /* SMB2Notification.swift in Sources */,
688682
799396D31D48C02300086753 /* SMB2SetInfo.swift in Sources */,
689683
7924B1981D89DAE000589DB7 /* Document.swift in Sources */,
@@ -802,6 +796,7 @@
802796
buildSettings = {
803797
ALWAYS_SEARCH_USER_PATHS = NO;
804798
APPLICATION_EXTENSION_API_ONLY = YES;
799+
BUNDLE_VERSION_STRING = 0.23.0;
805800
CLANG_ANALYZER_NONNULL = YES;
806801
CLANG_ENABLE_MODULES = YES;
807802
CLANG_ENABLE_OBJC_ARC = YES;
@@ -837,6 +832,7 @@
837832
buildSettings = {
838833
ALWAYS_SEARCH_USER_PATHS = NO;
839834
APPLICATION_EXTENSION_API_ONLY = YES;
835+
BUNDLE_VERSION_STRING = 0.23.0;
840836
CLANG_ANALYZER_NONNULL = YES;
841837
CLANG_ENABLE_MODULES = YES;
842838
CLANG_ENABLE_OBJC_ARC = YES;

Sources/CloudFileProvider.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ open class CloudFileProvider: LocalFileProvider, FileProviderSharing {
283283
return progress
284284
}
285285

286-
open override func isReachable(completionHandler: @escaping (Bool) -> Void) {
286+
open override func isReachable(completionHandler: @escaping (_ success: Bool, _ error: Error?) -> Void) {
287287
dispatch_queue.async {
288-
completionHandler(self.fileManager.ubiquityIdentityToken != nil)
288+
completionHandler(self.fileManager.ubiquityIdentityToken != nil, nil)
289289
}
290290
}
291291

Sources/FTPFileProvider.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ open class FTPFileProvider: FileProviderBasicRemote, FileProviderOperations, Fil
343343
return relativePath.replacingOccurrences(of: "/", with: "", options: .anchored)
344344
}
345345

346-
open func isReachable(completionHandler: @escaping (Bool) -> Void) {
346+
open func isReachable(completionHandler: @escaping (_ success: Bool, _ error: Error?) -> Void) {
347347
self.attributesOfItem(path: "/") { (file, error) in
348-
completionHandler(file != nil)
348+
completionHandler(file != nil, error)
349349
}
350350
}
351351

Sources/FileProvider.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public protocol FileProviderBasic: class, NSSecureCoding {
153153
/// - Note: To prevent race condition, use this method wisely and avoid it as far possible.
154154
///
155155
/// - Parameter success: indicated server is reachable or not.
156-
func isReachable(completionHandler: @escaping(_ success: Bool) -> Void)
156+
/// - Parameter error: `Error` returned by server if occured.
157+
func isReachable(completionHandler: @escaping(_ success: Bool, _ error: Error?) -> Void)
157158
}
158159

159160
extension FileProviderBasic {

Sources/HTTPFileProvider.swift

+9-2
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,16 @@ open class HTTPFileProvider: FileProviderBasicRemote, FileProviderOperations, Fi
153153
fatalError("HTTPFileProvider is an abstract class. Please implement \(#function) in subclass.")
154154
}
155155

156-
open func isReachable(completionHandler: @escaping (Bool) -> Void) {
156+
open func isReachable(completionHandler: @escaping (_ success: Bool, _ error: Error?) -> Void) {
157157
self.storageProperties { volume in
158-
completionHandler(volume != nil)
158+
if volume != nil {
159+
completionHandler(volume != nil, nil)
160+
return
161+
} else {
162+
self.contentsOfDirectory(path: "", completionHandler: { (files, error) in
163+
completionHandler(false, error)
164+
})
165+
}
159166
}
160167
}
161168

Sources/LocalFileProvider.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,14 @@ open class LocalFileProvider: FileProvider, FileProviderMonitor {
215215
return progress
216216
}
217217

218-
open func isReachable(completionHandler: @escaping (_ success: Bool) -> Void) {
218+
open func isReachable(completionHandler: @escaping (_ success: Bool, _ error: Error?) -> Void) {
219219
dispatch_queue.async {
220-
completionHandler(self.fileManager.isReadableFile(atPath: self.baseURL!.path))
220+
do {
221+
let isReachable = try self.baseURL!.checkResourceIsReachable()
222+
completionHandler(isReachable, nil)
223+
} catch {
224+
completionHandler(false, error)
225+
}
221226
}
222227
}
223228

Sources/OneDriveFileProvider.swift

+8-2
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,19 @@ open class OneDriveFileProvider: HTTPFileProvider, FileProviderSharing {
361361
/// - Note: To prevent race condition, use this method wisely and avoid it as far possible.
362362
///
363363
/// - Parameter success: indicated server is reachable or not.
364-
open override func isReachable(completionHandler: @escaping (Bool) -> Void) {
364+
open override func isReachable(completionHandler: @escaping (_ success: Bool, _ error: Error?) -> Void) {
365365
var request = URLRequest(url: url(of: ""))
366366
request.httpMethod = "HEAD"
367367
request.setValue(authentication: credential, with: .oAuth2)
368368
let task = session.dataTask(with: request, completionHandler: { (data, response, error) in
369369
let status = (response as? HTTPURLResponse)?.statusCode ?? 400
370-
completionHandler(status == 200)
370+
if status >= 400, let code = FileProviderHTTPErrorCode(rawValue: status) {
371+
let errorDesc = data.flatMap({ String(data: $0, encoding: .utf8) })
372+
let error = FileProviderOneDriveError(code: code, path: "", serverDescription: errorDesc)
373+
completionHandler(false, error)
374+
return
375+
}
376+
completionHandler(status == 200, error)
371377
})
372378
task.resume()
373379
}

Sources/SMBFileProvider.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SMBFileProvider: FileProvider, FileProviderMonitor {
6868
NotImplemented()
6969
}
7070

71-
func isReachable(completionHandler: @escaping (Bool) -> Void) {
71+
func isReachable(completionHandler: @escaping (_ success: Bool, _ error: Error?) -> Void) {
7272
NotImplemented()
7373
}
7474

Sources/WebDAVFileProvider.swift

+8-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ open class WebDAVFileProvider: HTTPFileProvider, FileProviderSharing {
267267
return progress
268268
}
269269

270-
override open func isReachable(completionHandler: @escaping (Bool) -> Void) {
270+
override open func isReachable(completionHandler: @escaping (_ success: Bool, _ error: Error?) -> Void) {
271271
var request = URLRequest(url: baseURL!)
272272
request.httpMethod = "PROPFIND"
273273
request.setValue("0", forHTTPHeaderField: "Depth")
@@ -276,7 +276,13 @@ open class WebDAVFileProvider: HTTPFileProvider, FileProviderSharing {
276276
request.httpBody = WebDavFileObject.xmlProp([.volumeTotalCapacityKey, .volumeAvailableCapacityKey])
277277
runDataTask(with: request, completionHandler: { (data, response, error) in
278278
let status = (response as? HTTPURLResponse)?.statusCode ?? 400
279-
completionHandler(status < 300)
279+
if status >= 400, let code = FileProviderHTTPErrorCode(rawValue: status) {
280+
let errorDesc = data.flatMap({ String(data: $0, encoding: .utf8) })
281+
let error = FileProviderWebDavError(code: code, path: "", serverDescription: errorDesc, url: self.baseURL!)
282+
completionHandler(false, error)
283+
return
284+
}
285+
completionHandler(status < 300, error)
280286
})
281287
}
282288

0 commit comments

Comments
 (0)