diff --git a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java index 4764565303d0be1f91f0c5a28357aeb5928bbfbc..75e09b3f02872dbfb2cf309aa732458988a46cda 100644 --- a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java +++ b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java @@ -252,11 +252,12 @@ public class UploadFileOperation extends RemoteOperation { @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) @NonNull public RemoteOperationResult uploadChunkedFile(@NonNull final File file, @NonNull final OwnCloudClient client) { + final String timeStamp = formatTimestampToMatchCloud(file.lastModified()); final String mimeType = CommonUtils.getMimeType(file); final ChunkedFileUploadRemoteOperation uploadOperation = new ChunkedFileUploadRemoteOperation(syncedState.getLocalPath(), syncedState.getRemotePath(), mimeType, syncedState.getLastETAG(), - syncedState.getLocalLastModified()+"", false); + timeStamp, false); return uploadOperation.execute(client); } @@ -305,7 +306,7 @@ public class UploadFileOperation extends RemoteOperation { @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) @NonNull public RemoteOperationResult uploadFile(@NonNull final File file, @NonNull final OwnCloudClient client, boolean checkEtag) { - final String timeStamp = ((Long) (file.lastModified() / 1000) ).toString(); + final String timeStamp = formatTimestampToMatchCloud(file.lastModified()); final String eTag = checkEtag ? syncedState.getLastETAG() : null; final UploadFileRemoteOperation uploadOperation = new UploadFileRemoteOperation(syncedState.getLocalPath(), @@ -334,4 +335,14 @@ public class UploadFileOperation extends RemoteOperation { public SyncedFileState getSyncedState() { return syncedState; } + + /** + * Convert local file timestamp to the format expected by the cloud + * On Android, file timestamp is a ms value, while nextcloud expect value in second + * @return String timestamp in second + */ + @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) + public @NonNull String formatTimestampToMatchCloud(long timestamp) { + return String.valueOf(timestamp/1000); + } } \ No newline at end of file diff --git a/app/src/test/java/foundation/e/drive/operations/UploadFileOperationTest.java b/app/src/test/java/foundation/e/drive/operations/UploadFileOperationTest.java index 2e2eaf48fd115b10bf4df22e242c05b00f051d8b..28d9f1d3619766084d3a2588d6dda8f8e6f579f2 100644 --- a/app/src/test/java/foundation/e/drive/operations/UploadFileOperationTest.java +++ b/app/src/test/java/foundation/e/drive/operations/UploadFileOperationTest.java @@ -314,6 +314,32 @@ public class UploadFileOperationTest { assertTrue("Expected result for ifMatchETagRequired(client) is true but got: false", addIfMatchHeader); } + @Test + public void formatTimeStampToMatchCloud_validTimestamp() { + final long initialTimestamp = 1683017095074L; + final String expectedOutput = "1683017095"; + final SyncedFileState mockedSyncedState = Mockito.mock(SyncedFileState.class); + final UploadFileOperation operationUnderTest = new UploadFileOperation(mockedSyncedState, account, context); + + final String output = operationUnderTest.formatTimestampToMatchCloud(initialTimestamp); + assertNotNull("Output shouldn't be null", output); + assertFalse("Output shouldn't not be empty.", output.isEmpty()); + assertEquals("Output doesn't match expectation.", expectedOutput, output); + } + + @Test + public void formatTimeStampToMatchCloud_invalidTimestamp() { + final long initialTimestamp = 0; + final String expectedOutput = "0"; + final SyncedFileState mockedSyncedState = Mockito.mock(SyncedFileState.class); + final UploadFileOperation operationUnderTest = new UploadFileOperation(mockedSyncedState, account, context); + + final String output = operationUnderTest.formatTimestampToMatchCloud(initialTimestamp); + assertNotNull("Output shouldn't be null", output); + assertFalse("Output shouldn't not be empty.", output.isEmpty()); + assertEquals("Output doesn't match expectation.", expectedOutput, output); + } + private void mockUserInfoReading(UploadFileOperation instanceUnderTest) { final long userTotalQuota = 100; final long userUsedQuota = 50;