Bläddra i källkod

Merge pull request #2048 from nextcloud/fix/e2ee

Fix/e2ee
Marino Faggiana 2 år sedan
förälder
incheckning
cd6a3c6763

+ 2 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -2996,6 +2996,7 @@
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_TESTABILITY = YES;
 				GCC_NO_COMMON_BLOCKS = YES;
+				GCC_OPTIMIZATION_LEVEL = 0;
 				GCC_PREPROCESSOR_DEFINITIONS = (
 					"$(inherited)",
 					DEBUG,
@@ -3055,6 +3056,7 @@
 				DEVELOPMENT_TEAM = 6JLRKY9ZV7;
 				ENABLE_BITCODE = YES;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
+				ENABLE_TESTABILITY = YES;
 				GCC_NO_COMMON_BLOCKS = YES;
 				GCC_PREPROCESSOR_DEFINITIONS = (
 					"$(inherited)",

+ 3 - 0
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -369,12 +369,15 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
               let fileNameView = userInfo["fileNameView"] as? String,
               let serverUrl = userInfo["serverUrl"] as? String,
               let account = userInfo["account"] as? String,
+              let onlyLocalCache = userInfo["onlyLocalCache"] as? Bool,
               (serverUrl == serverUrl && account == appDelegate.account)
         else {
             return
         }
         if fileNameView.lowercased() == NCGlobal.shared.fileNameRichWorkspace.lowercased() {
             reloadDataSourceNetwork(forced: true)
+        } else if onlyLocalCache {
+            self.collectionView?.reloadData()
         } else {
             let (indexPath, sameSections) = dataSource.deleteMetadata(ocId: ocId)
             if let indexPath = indexPath {

+ 1 - 1
iOSClient/Networking/NCNetworkingE2EE.swift

@@ -322,7 +322,7 @@ import Alamofire
                             NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocIdTemp))
                             NCManageDatabase.shared.addLocalFile(metadata: metadata)
 
-                            NCUtility.shared.createImageFrom(fileName: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
+                            NCUtility.shared.createImageFrom(fileNameView: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
 
                             NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadedFile, userInfo: ["ocId": metadata.ocId, "ocIdTemp": ocIdTemp, "errorCode": errorCode, "errorDescription": ""])
 

+ 15 - 6
iOSClient/Utility/CCUtility.m

@@ -1150,13 +1150,22 @@
 
 + (BOOL)fileProviderStorageExists:(tableMetadata *)metadata
 {
-    NSString *fileNamePath = [self getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView];
-    if (![[NSFileManager defaultManager] fileExistsAtPath:fileNamePath]) {
-        return false;
-    }
+    NSString *fileNameViewPath = [self getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView];
+    NSString *fileNamePath = [self getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileName];
+    BOOL isFolderEncrypted = [self isFolderEncrypted:metadata.serverUrl e2eEncrypted:metadata.e2eEncrypted account:metadata.account urlBase:metadata.urlBase];
 
-    unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileNamePath error:nil] fileSize];
-    return fileSize == metadata.size;
+    unsigned long long fileNameViewSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileNameViewPath error:nil] fileSize];
+    unsigned long long fileNameSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileNamePath error:nil] fileSize];
+
+    if (isFolderEncrypted == true) {
+        if (fileNameSize == metadata.size && fileNameViewSize > 0) {
+            return true;
+        } else {
+            return false;
+        }
+    } else {
+        return fileNameViewSize == metadata.size;
+    }
 }
 
 + (int64_t)fileProviderStorageSize:(NSString *)ocId fileNameView:(NSString *)fileNameView

+ 3 - 3
iOSClient/Utility/NCUtility+Image.swift

@@ -33,7 +33,7 @@ extension NCUtility {
         }
 
         if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue && !metadata.hasPreview {
-            NCUtility.shared.createImageFrom(fileName: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
+            NCUtility.shared.createImageFrom(fileNameView: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
         }
 
         if CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag) {
@@ -62,7 +62,7 @@ extension NCUtility {
 
             if ext == "GIF" {
                 if !FileManager().fileExists(atPath: previewPath) {
-                    NCUtility.shared.createImageFrom(fileName: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
+                    NCUtility.shared.createImageFrom(fileNameView: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
                 }
                 image = UIImage.animatedImage(withAnimatedGIFURL: URL(fileURLWithPath: imagePath))
             } else if ext == "SVG" {
@@ -82,7 +82,7 @@ extension NCUtility {
                     return nil
                 }
             } else {
-                NCUtility.shared.createImageFrom(fileName: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
+                NCUtility.shared.createImageFrom(fileNameView: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
                 image = UIImage(contentsOfFile: imagePath)
             }
         }

+ 3 - 4
iOSClient/Utility/NCUtility.swift

@@ -444,16 +444,15 @@ class NCUtility: NSObject {
         }
     }
 
-    func createImageFrom(fileName: String, ocId: String, etag: String, classFile: String) {
+    func createImageFrom(fileNameView: String, ocId: String, etag: String, classFile: String) {
 
         var originalImage, scaleImagePreview, scaleImageIcon: UIImage?
 
-        let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)!
+        let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView)!
         let fileNamePathPreview = CCUtility.getDirectoryProviderStoragePreviewOcId(ocId, etag: etag)!
         let fileNamePathIcon = CCUtility.getDirectoryProviderStorageIconOcId(ocId, etag: etag)!
 
-        if FileManager().fileExists(atPath: fileNamePathPreview) && FileManager().fileExists(atPath: fileNamePathIcon) { return }
-        if CCUtility.fileProviderStorageSize(ocId, fileNameView: fileName) != 0 { return }
+        if CCUtility.fileProviderStorageSize(ocId, fileNameView: fileNameView) > 0 && FileManager().fileExists(atPath: fileNamePathPreview) && FileManager().fileExists(atPath: fileNamePathIcon) { return }
         if classFile != NCCommunicationCommon.typeClassFile.image.rawValue && classFile != NCCommunicationCommon.typeClassFile.video.rawValue { return }
 
         if classFile == NCCommunicationCommon.typeClassFile.image.rawValue {

+ 3 - 3
iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift

@@ -292,7 +292,7 @@ class NCViewerMedia: UIViewController {
             }
 
             if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue && !metadata.hasPreview {
-                NCUtility.shared.createImageFrom(fileName: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
+                NCUtility.shared.createImageFrom(fileNameView: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
             }
 
             if CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag) {
@@ -322,7 +322,7 @@ class NCViewerMedia: UIViewController {
 
                 if ext == "GIF" {
                     if !FileManager().fileExists(atPath: previewPath) {
-                        NCUtility.shared.createImageFrom(fileName: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
+                        NCUtility.shared.createImageFrom(fileNameView: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
                     }
                     image = UIImage.animatedImage(withAnimatedGIFURL: URL(fileURLWithPath: imagePath))
                 } else if ext == "SVG" {
@@ -342,7 +342,7 @@ class NCViewerMedia: UIViewController {
                         return nil
                     }
                 } else {
-                    NCUtility.shared.createImageFrom(fileName: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
+                    NCUtility.shared.createImageFrom(fileNameView: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
                     image = UIImage(contentsOfFile: imagePath)
                 }
             }