Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7fd77c0e authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Fix qa report from 1.16 beta: prevent reupload of every file

parent 2d57f45f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ object FileDiffUtils {
    @JvmStatic
    fun getActionForFileDiff(remoteFile: RemoteFile, fileState: SyncedFileState): Action {
        if (!hasEtagChanged(remoteFile, fileState)) {
            if (isCorruptedTimestamp(remoteFile.modifiedTimestamp)) return Action.Upload
            if (isCorruptedTimestamp(remoteFile.modifiedTimestamp / 1000)) return Action.Upload

            if (hasAlreadyBeenDownloaded(fileState)) return Action.Skip
        }
+1 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ public class DownloadFileOperation extends RemoteOperation {
        }

        if (remoteFile.getModifiedTimestamp() < CORRUPTED_TIMESTAMP_IN_SECOND) {
            targetFile.setLastModified(remoteFile.getModifiedTimestamp() * 1000); //android uses timestamp in MS
            targetFile.setLastModified(remoteFile.getModifiedTimestamp());
        }
        syncedFileState.setLastModified(targetFile.lastModified());
        syncedFileState.setLastEtag(remoteFile.getEtag());
+1 −1
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation
        }

        if (!canStart(threadIndex) || isPaused()) {
            Timber.d("Can't start thread #%s", threadIndex);
            Timber.d("Can't start thread #%s, Sync is paused or thread is already running", threadIndex);
            return;
        }

+3 −3
Original line number Diff line number Diff line
@@ -269,7 +269,7 @@ internal class FileDiffUtilsTest {
    @Test
    fun `getActionForFileDiff(RemoteFile) return Upload when remote modifiedTimestamp is corrupted and eTag unchanged`() {
        val mockedRemoteFile = Mockito.mock(RemoteFile::class.java)
        Mockito.`when`(mockedRemoteFile.modifiedTimestamp).thenReturn(4294967295L)
        Mockito.`when`(mockedRemoteFile.modifiedTimestamp).thenReturn(4294967295000L)
        Mockito.`when`(mockedRemoteFile.etag).thenReturn("123456")
        val mockedFileState = Mockito.mock(SyncedFileState::class.java)
        Mockito.`when`(mockedFileState.lastEtag).thenReturn("123456")
@@ -280,7 +280,7 @@ internal class FileDiffUtilsTest {
    @Test
    fun `getActionForFileDiff(RemoteFile) don't return Upload when remote modifiedTimestamp is corrupted but eTag changed`() {
        val mockedRemoteFile = Mockito.mock(RemoteFile::class.java)
        Mockito.`when`(mockedRemoteFile.modifiedTimestamp).thenReturn(4294967295L)
        Mockito.`when`(mockedRemoteFile.modifiedTimestamp).thenReturn(4294967295000L)
        Mockito.`when`(mockedRemoteFile.etag).thenReturn("654321")
        val mockedFileState = Mockito.mock(SyncedFileState::class.java)
        Mockito.`when`(mockedFileState.lastEtag).thenReturn("123456789")
@@ -309,6 +309,6 @@ internal class FileDiffUtilsTest {
    fun `isCorruptedTimestamp() return false with timestamp smaller than max of Int32 `() {
        val corruptedTimestamp = 4294967295L - 1
        val resultUnderTest = FileDiffUtils.isCorruptedTimestamp(corruptedTimestamp)
        Assert.assertFalse("isCorruptedTimestamp(4294967295L) returned $resultUnderTest instead of false", resultUnderTest)
        Assert.assertFalse("isCorruptedTimestamp(4294967295000L) returned $resultUnderTest instead of false", resultUnderTest)
    }
}
 No newline at end of file