|
@@ -532,45 +532,33 @@ class NCUtilityFileSystem: NSObject {
|
|
let minimumDate = Date().addingTimeInterval(-days * 24 * 60 * 60)
|
|
let minimumDate = Date().addingTimeInterval(-days * 24 * 60 * 60)
|
|
let url = URL(fileURLWithPath: directory)
|
|
let url = URL(fileURLWithPath: directory)
|
|
var offlineDir: [String] = []
|
|
var offlineDir: [String] = []
|
|
- var offlineFiles: [String] = []
|
|
|
|
|
|
|
|
if let directories = NCManageDatabase.shared.getTablesDirectory(predicate: NSPredicate(format: "offline == true"), sorted: "serverUrl", ascending: true) {
|
|
if let directories = NCManageDatabase.shared.getTablesDirectory(predicate: NSPredicate(format: "offline == true"), sorted: "serverUrl", ascending: true) {
|
|
for directory: tableDirectory in directories {
|
|
for directory: tableDirectory in directories {
|
|
offlineDir.append(getDirectoryProviderStorageOcId(directory.ocId))
|
|
offlineDir.append(getDirectoryProviderStorageOcId(directory.ocId))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- let files = NCManageDatabase.shared.getTableLocalFiles(predicate: NSPredicate(format: "offline == true"), sorted: "fileName", ascending: true)
|
|
|
|
- for file: tableLocalFile in files {
|
|
|
|
- offlineFiles.append(getDirectoryProviderStorageOcId(file.ocId, fileNameView: file.fileName))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func meetsRequirement(date: Date) -> Bool {
|
|
|
|
- return date < minimumDate
|
|
|
|
- }
|
|
|
|
|
|
+ let resultsLocalFile = NCManageDatabase.shared.getResultsTableLocalFile(predicate: NSPredicate(format: "offline == false"), sorted: "lastOpeningDate", ascending: true)
|
|
|
|
|
|
let manager = FileManager.default
|
|
let manager = FileManager.default
|
|
if let enumerator = manager.enumerator(at: url, includingPropertiesForKeys: [.isRegularFileKey], options: []) {
|
|
if let enumerator = manager.enumerator(at: url, includingPropertiesForKeys: [.isRegularFileKey], options: []) {
|
|
for case let fileURL as URL in enumerator {
|
|
for case let fileURL as URL in enumerator {
|
|
if let attributes = try? manager.attributesOfItem(atPath: fileURL.path) {
|
|
if let attributes = try? manager.attributesOfItem(atPath: fileURL.path) {
|
|
- if let date = CCUtility.getATime(fileURL.path) {
|
|
|
|
- if attributes[.size] as? Double == 0 { continue }
|
|
|
|
- if attributes[.type] as? FileAttributeType == FileAttributeType.typeDirectory { continue }
|
|
|
|
- if fileURL.pathExtension == NCGlobal.shared.extensionPreview { continue }
|
|
|
|
- // check offline
|
|
|
|
- if offlineFiles.contains(fileURL.path) { continue }
|
|
|
|
- let filter = offlineDir.filter({ fileURL.path.hasPrefix($0)})
|
|
|
|
- if !filter.isEmpty { continue }
|
|
|
|
- // check date
|
|
|
|
- if meetsRequirement(date: date) {
|
|
|
|
- let folderURL = fileURL.deletingLastPathComponent()
|
|
|
|
- let ocId = folderURL.lastPathComponent
|
|
|
|
- do {
|
|
|
|
- try manager.removeItem(atPath: fileURL.path)
|
|
|
|
- } catch { }
|
|
|
|
- manager.createFile(atPath: fileURL.path, contents: nil, attributes: nil)
|
|
|
|
- NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", ocId))
|
|
|
|
- }
|
|
|
|
|
|
+ if attributes[.size] as? Double == 0 { continue }
|
|
|
|
+ if attributes[.type] as? FileAttributeType == FileAttributeType.typeDirectory { continue }
|
|
|
|
+ if fileURL.pathExtension == NCGlobal.shared.extensionPreview { continue }
|
|
|
|
+ // check directory offline
|
|
|
|
+ let filter = offlineDir.filter({ fileURL.path.hasPrefix($0)})
|
|
|
|
+ if !filter.isEmpty { continue }
|
|
|
|
+ // -----------------------
|
|
|
|
+ let folderURL = fileURL.deletingLastPathComponent()
|
|
|
|
+ let ocId = folderURL.lastPathComponent
|
|
|
|
+ if let result = resultsLocalFile?.filter({ $0.ocId == ocId }).first, (result.lastOpeningDate as Date) < minimumDate {
|
|
|
|
+ do {
|
|
|
|
+ try manager.removeItem(atPath: fileURL.path)
|
|
|
|
+ } catch { }
|
|
|
|
+ manager.createFile(atPath: fileURL.path, contents: nil, attributes: nil)
|
|
|
|
+ NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", ocId))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|