Skip to content

Commit 091fd14

Browse files
committed
OneDrive drive name bug fix. Added sorting method to [FileObject] array.
- now return `Error` for uploading a file with size higher than limit in OneDrive / Dropbox instead of asserting
1 parent 10aac53 commit 091fd14

7 files changed

Lines changed: 51 additions & 10 deletions

File tree

FileProvider.podspec

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

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

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

FileProvider.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@
595595
799396601D48B7BF00086753 /* Debug */ = {
596596
isa = XCBuildConfiguration;
597597
buildSettings = {
598-
BUNDLE_VERSION_STRING = 0.10.1;
598+
BUNDLE_VERSION_STRING = 0.10.2;
599599
CLANG_WARN_BOOL_CONVERSION = YES;
600600
CLANG_WARN_CONSTANT_CONVERSION = YES;
601601
CLANG_WARN_EMPTY_BODY = YES;
@@ -625,7 +625,7 @@
625625
799396611D48B7BF00086753 /* Release */ = {
626626
isa = XCBuildConfiguration;
627627
buildSettings = {
628-
BUNDLE_VERSION_STRING = 0.10.1;
628+
BUNDLE_VERSION_STRING = 0.10.2;
629629
CLANG_WARN_BOOL_CONVERSION = YES;
630630
CLANG_WARN_CONSTANT_CONVERSION = YES;
631631
CLANG_WARN_EMPTY_BODY = YES;

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@ Local and WebDAV providers are fully tested and can be used in production enviro
2626

2727
- [x] **LocalFileProvider** a wrapper around `FileManager` with some additions like searching and reading a portion of file.
2828
- [x] **WebDAVFileProvider** WebDAV protocol is defacto file transmission standard, replaced FTP.
29-
- [x] **DropboxFileProvider** A wrapper around Dropbox Web API. For now it has limitation in uploading files up to 150MB.
30-
- [x] **OneDriveFileProvider** A wrapper around OneDrive Web API, works with `onedrive.com` and compatible servers. For now it has limitation in uploading files up to 100MB.
31-
- [ ] **SMBFileProvider** SMB2/3 introduced in 2006, which is a file and printer sharing protocol originated from Microsoft Windows and now is replacing AFP protocol on MacOS. I implemented data types and some basic functions but *main interface is not implemented yet!* SMB1/CIFS is depericated and very tricky to be implemented
29+
- [x] **DropboxFileProvider** A wrapper around Dropbox Web API.
30+
* For now it has limitation in uploading files up to 150MB.
31+
- [x] **OneDriveFileProvider** A wrapper around OneDrive Web API, works with `onedrive.com` and compatible (business) servers.
32+
* For now it has limitation in uploading files up to 100MB.
33+
- [ ] **CloudFilePRovider** A wrapper around app's ubiquitous container to iCloud Drive in iOS 8+ API.
34+
- [ ] **SMBFileProvider** SMB2/3 introduced in 2006, which is a file and printer sharing protocol originated from Microsoft Windows and now is replacing AFP protocol on MacOS.
35+
* Data types and some basic functions are implemented but *main interface is not implemented yet!*
36+
* SMB1/CIFS is depericated and very tricky to be implemented
3237
- [ ] **FTPFileProvider** while deprecated in 1990s, it's still in use on some Web hosts.
3338
- [ ] **AmazonS3FileProvider**
39+
- [ ] **GoogleDriveFileProvider**
3440

3541
## Requirements
3642

Sources/DropboxHelper.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ internal extension DropboxFileProvider {
9898
}
9999

100100
func upload_simple(_ targetPath: String, data: Data, modifiedDate: Date = Date(), overwrite: Bool, operation: FileOperationType, completionHandler: SimpleCompletionHandler) -> OperationHandle? {
101-
assert(data.count < 150*1024*1024, "Maximum size of allowed size to upload is 150MB")
101+
if data.count > 150 * 1024 * 1024 {
102+
let error = FileProviderDropboxError(code: .payloadTooLarge, path: targetPath, errorDescription: nil)
103+
completionHandler?(error)
104+
self.delegateNotify(.create(path: targetPath), error: error)
105+
return nil
106+
}
102107
var requestDictionary = [String: Any]()
103108
let url: URL
104109
url = URL(string: "files/upload", relativeTo: contentURL)!
@@ -125,6 +130,13 @@ internal extension DropboxFileProvider {
125130
}
126131

127132
func upload_simple(_ targetPath: String, localFile: URL, modifiedDate: Date = Date(), overwrite: Bool, operation: FileOperationType, completionHandler: SimpleCompletionHandler) -> OperationHandle? {
133+
let size = (try? localFile.resourceValues(forKeys: [.fileSizeKey]))?.fileSize ?? -1
134+
if size > 150 * 1024 * 1024 {
135+
let error = FileProviderDropboxError(code: .payloadTooLarge, path: targetPath, errorDescription: nil)
136+
completionHandler?(error)
137+
self.delegateNotify(.create(path: targetPath), error: error)
138+
return nil
139+
}
128140
var requestDictionary = [String: Any]()
129141
let url: URL
130142
url = URL(string: "files/upload", relativeTo: contentURL)!

Sources/FileObject.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ open class FileObject {
135135
}
136136
}
137137

138-
/// Sorting FileObject array by given criteria, not thread-safe
138+
/// Sorting FileObject array by given criteria, **not thread-safe**
139139
public struct FileObjectSorting {
140140

141141
/// Determines sort kind by which item of File object
@@ -222,6 +222,17 @@ public struct FileObjectSorting {
222222
}
223223
}
224224

225+
extension Array where Element: FileObject {
226+
public func sorted(by type: FileObjectSorting.SortType, ascending: Bool = true, isDirectoriesFirst: Bool = false) -> [Element] {
227+
let sorting = FileObjectSorting(type: type, ascending: ascending, isDirectoriesFirst: isDirectoriesFirst)
228+
return sorting.sort(self) as! [Element]
229+
}
230+
231+
public mutating func sorted(by type: FileObjectSorting.SortType, ascending: Bool = true, isDirectoriesFirst: Bool = false) {
232+
self = self.sorted(by: type, ascending: ascending, isDirectoriesFirst: isDirectoriesFirst)
233+
}
234+
}
235+
225236
extension URLFileResourceType {
226237
public init(fileTypeValue: FileAttributeType) {
227238
switch fileTypeValue {

Sources/OneDriveFileProvide.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ open class OneDriveFileProvider: NSObject, FileProviderBasicRemote {
1919
open let baseURL: URL?
2020
open var drive: String
2121
open var driveURL: URL {
22-
return URL(string: "/drive/root:/", relativeTo: baseURL)!
22+
return URL(string: "/drive/\(drive):/", relativeTo: baseURL)!
2323
}
2424
open var currentPath: String = ""
2525

Sources/OneDriveHelper.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ internal extension OneDriveFileProvider {
9393
}
9494

9595
func upload_simple(_ targetPath: String, data: Data, modifiedDate: Date = Date(), overwrite: Bool, operation: FileOperationType, completionHandler: SimpleCompletionHandler) -> OperationHandle? {
96-
assert(data.count < 100*1024*1024, "Maximum size of allowed size to upload is 100MB")
96+
if data.count > 100 * 1024 * 1024 {
97+
let error = FileProviderOneDriveError(code: .payloadTooLarge, path: targetPath, errorDescription: nil)
98+
completionHandler?(error)
99+
self.delegateNotify(.create(path: targetPath), error: error)
100+
return nil
101+
}
97102
let queryStr = overwrite ? "" : "?@name.conflictBehavior=fail"
98103
let url = URL(string: escaped(path: targetPath) + ":/content" + queryStr, relativeTo: driveURL)!
99104
var request = URLRequest(url: url)
@@ -115,6 +120,13 @@ internal extension OneDriveFileProvider {
115120
}
116121

117122
func upload_simple(_ targetPath: String, localFile: URL, modifiedDate: Date = Date(), overwrite: Bool, operation: FileOperationType, completionHandler: SimpleCompletionHandler) -> OperationHandle? {
123+
let size = (try? localFile.resourceValues(forKeys: [.fileSizeKey]))?.fileSize ?? -1
124+
if size > 100 * 1024 * 1024 {
125+
let error = FileProviderOneDriveError(code: .payloadTooLarge, path: targetPath, errorDescription: nil)
126+
completionHandler?(error)
127+
self.delegateNotify(.create(path: targetPath), error: error)
128+
return nil
129+
}
118130
let queryStr = overwrite ? "" : "?@name.conflictBehavior=fail"
119131
let url = URL(string: escaped(path: targetPath) + ":/content" + queryStr, relativeTo: driveURL)!
120132
var request = URLRequest(url: url)

0 commit comments

Comments
 (0)