Commit 2fc314fe by Sarkizz

修正文件存在判断逻辑

parent 47c1daf4
......@@ -45,14 +45,18 @@ extension MRFiles {
/// - path: 文件路径
/// - isDirectory: 是否文件夹,传入true,则路径一定要是文件夹才会返回true。默认是false
/// - Returns: 文件是否存在,且是否跟传入的isDirectory相符
public class func fileExists(path: String, isDirectory: Bool = false) -> Bool {
public class func fileExists(path: String, isDirectory: Bool? = nil) -> Bool {
if let isDir = isDirectory {
var isDic: ObjCBool = false
let isDir = UnsafeMutablePointer<ObjCBool>(&isDic)
let isExists = FileManager.default.fileExists(atPath: path, isDirectory: isDir)
return isExists && (isDirectory == isDic.boolValue)
} else {
return FileManager.default.fileExists(atPath: path)
}
}
public class func fileExists(url: URL, isDirectory: Bool = false) -> Bool {
public class func fileExists(url: URL, isDirectory: Bool? = nil) -> Bool {
return fileExists(path: url.path, isDirectory: isDirectory)
}
}
......@@ -409,7 +413,7 @@ extension MRFiles {
// MARK: - 语法糖
extension String {
public func isPathExists(_ isDirectory: Bool = false) -> Bool {
public func isPathExists(_ isDirectory: Bool? = nil) -> Bool {
return MRFiles.fileExists(path: self, isDirectory: isDirectory)
}
......@@ -436,7 +440,7 @@ extension String {
}
extension URL {
public func isURLExists(_ isDirectory: Bool = false) -> Bool {
public func isURLExists(_ isDirectory: Bool? = nil) -> Bool {
return MRFiles.fileExists(url: self, isDirectory: isDirectory)
}
......
......@@ -154,7 +154,16 @@ extension MRUpdateManager {
case .appUpgrade:
if let bundleWWW = bundleWWWURL {
asyncIfNeeded {
let error = self.sandboxUpdateURL.syncDelete() ?? self.sandboxBackupURL.syncDelete() ?? bundleWWW.syncCopy(to: self.sandboxSrcURL)
var error: Error?
if self.sandboxUpdateURL.isURLExists(true) {
error = self.sandboxUpdateURL.syncDelete()
}
if error == nil && self.sandboxBackupURL.isURLExists(true) {
error = self.sandboxBackupURL.syncDelete()
}
if error == nil {
error = bundleWWW.syncCopy(to: self.sandboxSrcURL)
}
self.asyncInMain {
complate?(self, error)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment