marinofaggiana 3 年 前
コミット
26d1d26406

+ 6 - 5
iOSClient/AppDelegate.swift

@@ -182,11 +182,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             }
         }
         
-        // Clear file
-        if let directory = CCUtility.getDirectoryProviderStorage() {
-            NCUtilityFileSystem.shared.getCleanUp(directory: directory, days: 1)
-        }
-        
         // Passcode
         DispatchQueue.main.async {
             self.passcodeWithAutomaticallyPromptForBiometricValidation(true)
@@ -257,6 +252,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                 self.activeFileViewInFolder = nil
             })
         }
+        
+        // Clear older files
+        let days = CCUtility.getCleanUpDay()
+        if let directory = CCUtility.getDirectoryProviderStorage() {
+            NCUtilityFileSystem.shared.cleanUp(directory: directory, days: TimeInterval(days))
+        }
     }
     
     // L' applicazione è entrata nello sfondo

+ 3 - 0
iOSClient/Utility/CCUtility.h

@@ -178,6 +178,9 @@
 + (NSInteger)getChunkSize;
 + (void)setChunkSize:(NSInteger)size;
 
++ (NSInteger)getCleanUpDay;
++ (void)setCleanUpDay:(NSInteger)days;
+
 // ===== Varius =====
 
 + (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL;

+ 17 - 0
iOSClient/Utility/CCUtility.m

@@ -727,6 +727,23 @@
     [UICKeyChainStore setString:sizeString forKey:@"chunkSize" service:NCGlobal.shared.serviceShareKeyChain];
 }
 
++ (NSInteger)getCleanUpDay
+{
+    NSString *size = [UICKeyChainStore stringForKey:@"cleanUpDay" service:NCGlobal.shared.serviceShareKeyChain];
+    
+    if (size == nil) {
+        return 0;
+    } else {
+        return [size integerValue];
+    }
+}
+
++ (void)setCleanUpDay:(NSInteger)days
+{
+    NSString *daysString = [@(days) stringValue];
+    [UICKeyChainStore setString:daysString forKey:@"cleanUpDay" service:NCGlobal.shared.serviceShareKeyChain];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Various =====
 #pragma --------------------------------------------------------------------------------------------

+ 7 - 5
iOSClient/Utility/NCUtilityFileSystem.swift

@@ -242,6 +242,8 @@ class NCUtilityFileSystem: NSObject {
     
     func cleanUp(directory: String, days: TimeInterval) {
         
+        if days == 0 { return}
+        
         let minimumDate = Date().addingTimeInterval(-days*24*60*60)
         let url = URL(fileURLWithPath: directory)
         
@@ -254,14 +256,14 @@ class NCUtilityFileSystem: NSObject {
             for case let fileURL as URL in enumerator {
                 if let attributes = try? manager.attributesOfItem(atPath: fileURL.path) {
                     if let date = CCUtility.getATime(fileURL.path) {
-                        
-                        let folderURL = fileURL.deletingLastPathComponent()
-                        let ocId = folderURL.lastPathComponent
-                        
                         if attributes[.size] as? Double == 0 { continue }
                         if attributes[.type] as? FileAttributeType == FileAttributeType.typeDirectory { continue }
+                        if fileURL.pathExtension == "ico" { continue }
                         if meetsRequirement(date: date) {
                             do {
+                                let folderURL = fileURL.deletingLastPathComponent()
+                                let ocId = folderURL.lastPathComponent
+                                
                                 try manager.removeItem(atPath: folderURL.path)
                                 NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", ocId))
                             } catch {
@@ -271,7 +273,7 @@ class NCUtilityFileSystem: NSObject {
                     }
                 }
             }
-        }        
+        }
     }
 }