Fix remote session crash, minor fixes
This commit is contained in:
@@ -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: "/")!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user