فهرست منبع

Make use of upload and creation timestamp

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 3 سال پیش
والد
کامیت
607d008a75

+ 56 - 0
src/androidTest/java/com/owncloud/android/UploadIT.java

@@ -43,6 +43,10 @@ import org.junit.Test;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 import androidx.annotation.NonNull;
 
@@ -416,6 +420,58 @@ public class UploadIT extends AbstractOnServerIT {
         assertEquals(RemoteOperationResult.ResultCode.DELAYED_FOR_WIFI, result.getCode());
     }
 
+    @Test
+    public void testCreationAndUploadTimestamp() throws IOException {
+        File file = getDummyFile("/empty.txt");
+        String remotePath = "/testFile.txt";
+        OCUpload ocUpload = new OCUpload(file.getAbsolutePath(), remotePath, account.name);
+
+        assertTrue(
+            new UploadFileOperation(
+                uploadsStorageManager,
+                connectivityServiceMock,
+                powerManagementServiceMock,
+                user,
+                null,
+                ocUpload,
+                NameCollisionPolicy.DEFAULT,
+                FileUploader.LOCAL_BEHAVIOUR_COPY,
+                targetContext,
+                false,
+                false,
+                getStorageManager()
+            )
+                .setRemoteFolderToBeCreated()
+                .execute(client)
+                .isSuccess()
+                  );
+
+        long creationTimestamp = Files.readAttributes(file.toPath(), BasicFileAttributes.class)
+            .creationTime()
+            .to(TimeUnit.SECONDS);
+
+        long uploadTimestamp = System.currentTimeMillis() / 1000;
+
+        // RefreshFolderOperation
+        assertTrue(new RefreshFolderOperation(getStorageManager().getFileByDecryptedRemotePath("/"),
+                                              System.currentTimeMillis() / 1000,
+                                              false,
+                                              false,
+                                              getStorageManager(),
+                                              user,
+                                              targetContext).execute(client).isSuccess());
+
+        List<OCFile> files = getStorageManager().getFolderContent(getStorageManager().getFileByDecryptedRemotePath("/"),
+                                                                  false);
+
+        OCFile ocFile = files.get(0);
+
+        assertEquals(remotePath, ocFile.getRemotePath());
+        assertEquals(creationTimestamp, ocFile.getCreationTimestamp());
+        assertTrue(uploadTimestamp - 10 < ocFile.getUploadTimestamp() ||
+                       uploadTimestamp + 10 > ocFile.getUploadTimestamp());
+    }
+
     private void verifyStoragePath(OCFile file) {
         assertEquals(FileStorageUtils.getSavePath(account.name) + FOLDER + file.getDecryptedFileName(),
                      file.getStoragePath());

+ 8 - 2
src/main/java/com/owncloud/android/datamodel/OCFile.java

@@ -61,8 +61,10 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
     private long fileLength;
     private long creationTimestamp; // UNIX timestamp of the time the file was created
     private long modificationTimestamp; // UNIX timestamp of the file modification time
-    /** UNIX timestamp of the modification time, corresponding to the value returned by the server
-     * in the last synchronization of THE CONTENTS of this file.
+    private long uploadTimestamp;
+    /**
+     * UNIX timestamp of the modification time, corresponding to the value returned by the server in the last
+     * synchronization of THE CONTENTS of this file.
      */
     private long modificationTimestampAtLastSyncForData;
     private String remotePath;
@@ -607,6 +609,10 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
         return this.modificationTimestamp;
     }
 
+    public long getUploadTimestamp() {
+        return this.uploadTimestamp;
+    }
+
     public long getModificationTimestampAtLastSyncForData() {
         return this.modificationTimestampAtLastSyncForData;
     }