Fix remote session crash, minor fixes

This commit is contained in:
Amir Abbas
2018-07-26 13:18:49 +04:30
parent e2572d2810
commit 38fb3fc89a
4 changed files with 12 additions and 4 deletions
+4 -1
View File
@@ -34,7 +34,10 @@ open class FileObject: NSObject {
if let url = allValues[.fileURLKey] as? URL {
return url
} else {
let path = self.path.addingPercentEncoding(withAllowedCharacters: .filePathAllowed) ?? self.path
var path = self.path.addingPercentEncoding(withAllowedCharacters: .filePathAllowed) ?? self.path
if path.hasPrefix("/") {
path.remove(at: path.startIndex)
}
return URL(string: path) ?? URL(string: "/")!
}
}
+1 -1
View File
@@ -786,7 +786,7 @@ public extension FileProviderBasic {
public func url(of path: String) -> URL {
var rpath: String = path
rpath = rpath.addingPercentEncoding(withAllowedCharacters: .filePathAllowed) ?? rpath
if let baseURL = baseURL {
if let baseURL = baseURL?.absoluteURL {
if rpath.hasPrefix("/") {
rpath.remove(at: rpath.startIndex)
}
+4 -1
View File
@@ -126,7 +126,10 @@ public final class LocalFileMonitor {
/// Creates a folder monitor object with monitoring enabled.
public init?(url: URL, handler: @escaping ()->Void) {
self.url = url
descriptor = open((url.absoluteURL as NSURL).fileSystemRepresentation, O_EVTONLY)
descriptor = url.absoluteURL.withUnsafeFileSystemRepresentation { rep in
guard let rep = rep else { return -1 }
return open(rep, O_EVTONLY)
}
guard descriptor >= 0 else { return nil }
let event: DispatchSource.FileSystemEvent = url.fileIsDirectory ? [.write] : .all
source = DispatchSource.makeFileSystemObjectSource(fileDescriptor: descriptor, eventMask: event, queue: qq)
+3 -1
View File
@@ -62,7 +62,9 @@ final public class SessionDelegate: NSObject, URLSessionDataDelegate, URLSession
}
public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let progress = context?.load(as: Progress.self), let newVal = change?[.newKey] as? Int64 {
if let progress = context?.assumingMemoryBound(to: Progress.self).pointee,
progress.responds(to: #selector(Progress.becomeCurrent(withPendingUnitCount:))),
let newVal = change?[.newKey] as? Int64 {
switch keyPath ?? "" {
case #keyPath(URLSessionTask.countOfBytesReceived):
progress.completedUnitCount = newVal