Browse Source

Add correct decryptedRemotePath for v1

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 year ago
parent
commit
7d9a8f1d9f

+ 17 - 1
app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java

@@ -585,6 +585,7 @@ public class RefreshFolderOperation extends RemoteOperation {
         return metadata;
         return metadata;
     }
     }
 
 
+    // TODO write test for decryptedRemotePath existence...
     public static void updateFileNameForEncryptedFileV1(FileDataStorageManager storageManager,
     public static void updateFileNameForEncryptedFileV1(FileDataStorageManager storageManager,
                                                         @NonNull DecryptedFolderMetadataFileV1 metadata,
                                                         @NonNull DecryptedFolderMetadataFileV1 metadata,
                                                         OCFile updatedFile) {
                                                         OCFile updatedFile) {
@@ -598,13 +599,28 @@ public class RefreshFolderOperation extends RemoteOperation {
             } else {
             } else {
                 com.owncloud.android.datamodel.e2e.v1.decrypted.DecryptedFile decryptedFile =
                 com.owncloud.android.datamodel.e2e.v1.decrypted.DecryptedFile decryptedFile =
                     metadata.getFiles().get(updatedFile.getFileName());
                     metadata.getFiles().get(updatedFile.getFileName());
+
+                if (decryptedFile == null) {
+                    throw new NullPointerException("decryptedFile cannot be null");
+                }
+
                 decryptedFileName = decryptedFile.getEncrypted().getFilename();
                 decryptedFileName = decryptedFile.getEncrypted().getFilename();
                 mimetype = decryptedFile.getEncrypted().getMimetype();
                 mimetype = decryptedFile.getEncrypted().getMimetype();
             }
             }
 
 
 
 
             OCFile parentFile = storageManager.getFileById(updatedFile.getParentId());
             OCFile parentFile = storageManager.getFileById(updatedFile.getParentId());
-            String decryptedRemotePath = parentFile.getDecryptedRemotePath() + decryptedFileName;
+
+            if (parentFile == null) {
+                throw new NullPointerException("parentFile cannot be null");
+            }
+
+            String decryptedRemotePath;
+            if (decryptedFileName != null) {
+                decryptedRemotePath = parentFile.getDecryptedRemotePath() + decryptedFileName;
+            } else {
+                decryptedRemotePath = parentFile.getRemotePath() + updatedFile.getFileName();
+            }
 
 
             if (updatedFile.isFolder()) {
             if (updatedFile.isFolder()) {
                 decryptedRemotePath += "/";
                 decryptedRemotePath += "/";