diff --git a/FileProvider.podspec b/FileProvider.podspec index 42a9039..c6f2caa 100644 --- a/FileProvider.podspec +++ b/FileProvider.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "FileProvider" - s.version = "0.7.1" + s.version = "0.7.2" s.summary = "FileManager replacement for Local and Remote (WebDAV/Dropbox/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 25defbe..bc8808c 100644 --- a/FileProvider.xcodeproj/project.pbxproj +++ b/FileProvider.xcodeproj/project.pbxproj @@ -557,7 +557,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; APPLICATION_EXTENSION_API_ONLY = YES; - BUNDLE_VERSION_STRING = 0.7.1; + BUNDLE_VERSION_STRING = 0.7.2; CLANG_ANALYZER_NONNULL = YES; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -610,7 +610,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; APPLICATION_EXTENSION_API_ONLY = YES; - BUNDLE_VERSION_STRING = 0.7.1; + BUNDLE_VERSION_STRING = 0.7.2; CLANG_ANALYZER_NONNULL = YES; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; diff --git a/Sources/LocalFileProvider.swift b/Sources/LocalFileProvider.swift index c7b5520..1366177 100644 --- a/Sources/LocalFileProvider.swift +++ b/Sources/LocalFileProvider.swift @@ -67,23 +67,14 @@ open class LocalFileProvider: FileProvider, FileProviderMonitor { } internal func attributesOfItem(url fileURL: URL) -> LocalFileObject { - var namev, sizev, allocated, filetypev, creationDatev, modifiedDatev, hiddenv, readonlyv: AnyObject? - _ = try? (fileURL as NSURL).getResourceValue(&namev, forKey: URLResourceKey.nameKey) - _ = try? (fileURL as NSURL).getResourceValue(&sizev, forKey: URLResourceKey.fileSizeKey) - _ = try? (fileURL as NSURL).getResourceValue(&allocated, forKey: URLResourceKey.fileAllocatedSizeKey) - _ = try? (fileURL as NSURL).getResourceValue(&creationDatev, forKey: URLResourceKey.creationDateKey) - _ = try? (fileURL as NSURL).getResourceValue(&modifiedDatev, forKey: URLResourceKey.contentModificationDateKey) - _ = try? (fileURL as NSURL).getResourceValue(&filetypev, forKey: URLResourceKey.fileResourceTypeKey) - _ = try? (fileURL as NSURL).getResourceValue(&hiddenv, forKey: URLResourceKey.isHiddenKey) - _ = try? (fileURL as NSURL).getResourceValue(&readonlyv, forKey: URLResourceKey.volumeIsReadOnlyKey) + let values = try? fileURL.resourceValues(forKeys: [.nameKey, .fileSizeKey, .fileAllocatedSizeKey, .creationDateKey, .contentModificationDateKey, .fileResourceTypeKey, .isHiddenKey, .volumeIsReadOnlyKey]) let path: String if isPathRelative { path = self.relativePathOf(url: fileURL) } else { path = fileURL.path } - let filetype = URLFileResourceType(rawValue: filetypev as? String ?? "") - let fileAttr = LocalFileObject(absoluteURL: fileURL, name: namev as! String, path: path, size: sizev?.int64Value ?? -1, allocatedSize: allocated?.int64Value ?? -1, createdDate: creationDatev as? Date, modifiedDate: modifiedDatev as? Date, fileType: FileType(urlResourceTypeValue: filetype), isHidden: hiddenv?.boolValue ?? false, isReadOnly: readonlyv?.boolValue ?? false) + let fileAttr = LocalFileObject(absoluteURL: fileURL, name: values?.name ?? fileURL.lastPathComponent, path: path, size: Int64(values?.fileSize ?? -1), allocatedSize: Int64(values?.fileAllocatedSize ?? -1), createdDate: values?.creationDate, modifiedDate: values?.contentModificationDate, fileType: FileType(urlResourceTypeValue: values?.fileResourceType ?? .unknown), isHidden: values?.isHidden ?? false, isReadOnly: values?.isWritable ?? false) return fileAttr } @@ -127,21 +118,8 @@ open class LocalFileProvider: FileProvider, FileProviderMonitor { let opType = FileOperationType.create(path: (atPath as NSString).appendingPathComponent(fileName)) operation_queue.async { let fileURL = self.absoluteURL(atPath).appendingPathComponent(fileName) - /*var attributes = [String : Any]() - if let createdDate = fileAttribs.createdDate { - attributes[FileAttributeKey.creationDate.rawValue] = createdDate as NSDate - } - if let modDate = fileAttribs.modifiedDate { - attributes[FileAttributeKey.modificationDate.rawValue] = modDate as NSDate - } - if fileAttribs.isReadOnly { - attributes[FileAttributeKey.posixPermissions.rawValue] = NSNumber(value: 365 as Int16) - }*/ - let success = self.opFileManager.createFile(atPath: fileURL.path, contents: data, attributes: nil/*attributes*/) + let success = self.opFileManager.createFile(atPath: fileURL.path, contents: data, attributes: nil) if success { - /*do { - try (fileURL as NSURL).setResourceValue(fileAttribs.isHidden, forKey: URLResourceKey.isHiddenKey) - } catch _ {}*/ completionHandler?(nil) DispatchQueue.main.async(execute: { self.delegate?.fileproviderSucceed(self, operation: opType) @@ -332,12 +310,8 @@ open class LocalFileProvider: FileProvider, FileProviderMonitor { open func registerNotifcation(path: String, eventHandler: @escaping (() -> Void)) { self.unregisterNotifcation(path: path) let absurl = self.absoluteURL(path) - var isdirv: AnyObject? - do { - try (absurl as NSURL).getResourceValue(&isdirv, forKey: URLResourceKey.isDirectoryKey) - } catch _ { - } - if !(isdirv?.boolValue ?? false) { + let isdir = (try? absurl.resourceValues(forKeys: [.isDirectoryKey]).isDirectory ?? false) ?? false + if !isdir { return } let monitor = LocalFolderMonitor(url: absurl) { @@ -602,23 +576,18 @@ open class LocalOperationHandle: OperationHandle { let fp = FileManager() let filesList = fp.enumerator(at: pathURL, includingPropertiesForKeys: keys, options: enumOpt, errorHandler: nil) while let fileURL = filesList?.nextObject() as? URL { - var isdirv, sizev: AnyObject? do { - try (fileURL as NSURL).getResourceValue(&isdirv, forKey: URLResourceKey.isDirectoryKey) - } catch _ { - } - do { - try (fileURL as NSURL).getResourceValue(&sizev, forKey: URLResourceKey.fileSizeKey) + let values = try fileURL.resourceValues(forKeys: [.isDirectoryKey, .fileSizeKey]) + let isdir = values.isDirectory ?? false + let size = Int64(values.fileSize ?? 0) + if isdir { + folders += 1 + } else { + files += 1 + } + totalsize += size } catch _ { } - let isdir = isdirv?.boolValue ?? false - let size = sizev?.int64Value ?? 0 - if isdir { - folders += 1 - } else { - files += 1 - } - totalsize += size } return (folders, files, totalsize) @@ -628,27 +597,14 @@ open class LocalOperationHandle: OperationHandle { internal extension URL { var fileIsDirectory: Bool { - var isdirv: AnyObject? - do { - try (self as NSURL).getResourceValue(&isdirv, forKey: URLResourceKey.isDirectoryKey) - } catch _ { - } - return isdirv?.boolValue ?? false + return (try? self.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false } var fileSize: Int64 { - var sizev: AnyObject? - do { - try (self as NSURL).getResourceValue(&sizev, forKey: URLResourceKey.fileSizeKey) - } catch _ { - } - return sizev?.int64Value ?? -1 + return Int64((try? self.resourceValues(forKeys: [.fileSizeKey]))?.fileSize ?? -1) } var fileExists: Bool { - if self.isFileURL { - return FileManager.default.fileExists(atPath: self.path) - } - return false + return self.isFileURL && FileManager.default.fileExists(atPath: self.path) } } diff --git a/Sources/WebDAVFileProvider.swift b/Sources/WebDAVFileProvider.swift index 96d7019..282f175 100644 --- a/Sources/WebDAVFileProvider.swift +++ b/Sources/WebDAVFileProvider.swift @@ -181,7 +181,7 @@ extension WebDAVFileProvider: FileProviderOperations { guard fileOperationDelegate?.fileProvider(self, shouldDoOperation: opType) ?? true == true else { return nil } - let url = absoluteURL(path) + let url = absoluteURL(path).appendingPathComponent(fileName) var request = URLRequest(url: url) request.httpMethod = "PUT" let task = session.uploadTask(with: request, from: data, completionHandler: { (data, response, error) in