Loading app/src/main/java/foundation/e/drive/periodicScan/contentScanner/FileDiffUtils.kt +4 −4 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ object FileDiffUtils { @JvmStatic fun getActionForFileDiff(remoteFile: RemoteFile, fileState: SyncedFileState): Action { if (!hasEtagChanged(remoteFile, fileState)) { if (isCorruptedTimestamp(remoteFile.modifiedTimestamp / 1000)) return Action.Upload if (isCorruptedTimestamp(remoteFile.modifiedTimestamp)) return Action.Upload if (hasAlreadyBeenDownloaded(fileState)) return Action.Skip } Loading Loading @@ -93,13 +93,13 @@ object FileDiffUtils { * * For yet unknown reason, some remote files have this value on cloud (DB & file system) * the only way to fix them is to force re upload of the file with correct value * @param timestampInSecond remote file timestamp (Long) * @param timestampInMillisecond remote file timestamp (Long) * @return true if the timestamp is equal to max of unsigned int 32 */ @VisibleForTesting @JvmStatic fun isCorruptedTimestamp(timestampInSecond: Long): Boolean { return timestampInSecond >= AppConstants.CORRUPTED_TIMESTAMP_IN_SECOND fun isCorruptedTimestamp(timestampInMillisecond: Long): Boolean { return timestampInMillisecond >= AppConstants.CORRUPTED_TIMESTAMP_IN_MILLISECOND } /** Loading app/src/main/java/foundation/e/drive/synchronization/tasks/DownloadFileOperation.java +7 −3 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import static foundation.e.drive.utils.AppConstants.CORRUPTED_TIMESTAMP_IN_SECOND; import static foundation.e.drive.utils.AppConstants.CORRUPTED_TIMESTAMP_IN_MILLISECOND; import android.content.Context; import android.media.MediaScannerConnection; Loading Loading @@ -159,7 +159,7 @@ public class DownloadFileOperation extends RemoteOperation { return FORBIDDEN; } if (remoteFile.getModifiedTimestamp() < CORRUPTED_TIMESTAMP_IN_SECOND) { if (remoteFile.getModifiedTimestamp() < CORRUPTED_TIMESTAMP_IN_MILLISECOND) { targetFile.setLastModified(remoteFile.getModifiedTimestamp()); } syncedFileState.setLastModified(targetFile.lastModified()); Loading @@ -185,10 +185,14 @@ public class DownloadFileOperation extends RemoteOperation { final Path tmpPath = tmpFile.toPath(); final Path copyResult = Files.copy(tmpPath, targetPath, REPLACE_EXISTING); if (copyResult.toFile().length() == tmpFile.length()) { final File copyResultFile = copyResult.toFile(); if (copyResultFile.length() == tmpFile.length()) { tmpFile.delete(); return true; } copyResultFile.delete(); } catch (NoSuchFileException exception) { Timber.w(exception); } catch (IOException | SecurityException | NullPointerException exception) { Loading app/src/main/java/foundation/e/drive/utils/AppConstants.kt +1 −1 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ object AppConstants { const val notificationChannelID = "foundation.e.drive" const val WORK_GENERIC_TAG = "eDrive" const val WORK_SETUP_TAG = "eDrive-init" const val CORRUPTED_TIMESTAMP_IN_SECOND = 4294967295L const val CORRUPTED_TIMESTAMP_IN_MILLISECOND = 4294967295000L @JvmField val USER_AGENT = "eos(" + buildTime + ")-eDrive(" + BuildConfig.VERSION_NAME + ")" Loading app/src/test/java/foundation/e/drive/periodicScan/contentScanner/FileDiffUtilsTest.kt +6 −5 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ package foundation.e.drive.periodicScan.contentScanner import com.owncloud.android.lib.resources.files.model.RemoteFile import foundation.e.drive.models.SyncedFileState import foundation.e.drive.periodicScan.contentScanner.FileDiffUtils import foundation.e.drive.utils.AppConstants import org.junit.Assert import org.junit.Test import org.mockito.Mockito Loading Loading @@ -294,21 +295,21 @@ internal class FileDiffUtilsTest { /* isCorruptedTimestamp for localFile */ @Test fun `isCorruptedTimestamp() return true with timestamp equal to max of Int32 `() { val corruptedTimestamp = 4294967295L val corruptedTimestamp = AppConstants.CORRUPTED_TIMESTAMP_IN_MILLISECOND val resultUnderTest = FileDiffUtils.isCorruptedTimestamp(corruptedTimestamp) Assert.assertTrue("isCorruptedTimestamp(4294967295L) returned $resultUnderTest instead of true", resultUnderTest) Assert.assertTrue("isCorruptedTimestamp(4294967295000L) returned $resultUnderTest instead of true", resultUnderTest) } @Test fun `isCorruptedTimestamp() return true with timestamp bigger than max of Int32 `() { val corruptedTimestamp = 4294967295L + 1 val corruptedTimestamp = AppConstants.CORRUPTED_TIMESTAMP_IN_MILLISECOND + 1 val resultUnderTest = FileDiffUtils.isCorruptedTimestamp(corruptedTimestamp) Assert.assertTrue("isCorruptedTimestamp(4294967295L) returned $resultUnderTest instead of true", resultUnderTest) Assert.assertTrue("isCorruptedTimestamp(4294967295000L) returned $resultUnderTest instead of true", resultUnderTest) } @Test fun `isCorruptedTimestamp() return false with timestamp smaller than max of Int32 `() { val corruptedTimestamp = 4294967295L - 1 val corruptedTimestamp = AppConstants.CORRUPTED_TIMESTAMP_IN_MILLISECOND - 1 val resultUnderTest = FileDiffUtils.isCorruptedTimestamp(corruptedTimestamp) Assert.assertFalse("isCorruptedTimestamp(4294967295000L) returned $resultUnderTest instead of false", resultUnderTest) } Loading Loading
app/src/main/java/foundation/e/drive/periodicScan/contentScanner/FileDiffUtils.kt +4 −4 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ object FileDiffUtils { @JvmStatic fun getActionForFileDiff(remoteFile: RemoteFile, fileState: SyncedFileState): Action { if (!hasEtagChanged(remoteFile, fileState)) { if (isCorruptedTimestamp(remoteFile.modifiedTimestamp / 1000)) return Action.Upload if (isCorruptedTimestamp(remoteFile.modifiedTimestamp)) return Action.Upload if (hasAlreadyBeenDownloaded(fileState)) return Action.Skip } Loading Loading @@ -93,13 +93,13 @@ object FileDiffUtils { * * For yet unknown reason, some remote files have this value on cloud (DB & file system) * the only way to fix them is to force re upload of the file with correct value * @param timestampInSecond remote file timestamp (Long) * @param timestampInMillisecond remote file timestamp (Long) * @return true if the timestamp is equal to max of unsigned int 32 */ @VisibleForTesting @JvmStatic fun isCorruptedTimestamp(timestampInSecond: Long): Boolean { return timestampInSecond >= AppConstants.CORRUPTED_TIMESTAMP_IN_SECOND fun isCorruptedTimestamp(timestampInMillisecond: Long): Boolean { return timestampInMillisecond >= AppConstants.CORRUPTED_TIMESTAMP_IN_MILLISECOND } /** Loading
app/src/main/java/foundation/e/drive/synchronization/tasks/DownloadFileOperation.java +7 −3 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import static foundation.e.drive.utils.AppConstants.CORRUPTED_TIMESTAMP_IN_SECOND; import static foundation.e.drive.utils.AppConstants.CORRUPTED_TIMESTAMP_IN_MILLISECOND; import android.content.Context; import android.media.MediaScannerConnection; Loading Loading @@ -159,7 +159,7 @@ public class DownloadFileOperation extends RemoteOperation { return FORBIDDEN; } if (remoteFile.getModifiedTimestamp() < CORRUPTED_TIMESTAMP_IN_SECOND) { if (remoteFile.getModifiedTimestamp() < CORRUPTED_TIMESTAMP_IN_MILLISECOND) { targetFile.setLastModified(remoteFile.getModifiedTimestamp()); } syncedFileState.setLastModified(targetFile.lastModified()); Loading @@ -185,10 +185,14 @@ public class DownloadFileOperation extends RemoteOperation { final Path tmpPath = tmpFile.toPath(); final Path copyResult = Files.copy(tmpPath, targetPath, REPLACE_EXISTING); if (copyResult.toFile().length() == tmpFile.length()) { final File copyResultFile = copyResult.toFile(); if (copyResultFile.length() == tmpFile.length()) { tmpFile.delete(); return true; } copyResultFile.delete(); } catch (NoSuchFileException exception) { Timber.w(exception); } catch (IOException | SecurityException | NullPointerException exception) { Loading
app/src/main/java/foundation/e/drive/utils/AppConstants.kt +1 −1 Original line number Diff line number Diff line Loading @@ -38,7 +38,7 @@ object AppConstants { const val notificationChannelID = "foundation.e.drive" const val WORK_GENERIC_TAG = "eDrive" const val WORK_SETUP_TAG = "eDrive-init" const val CORRUPTED_TIMESTAMP_IN_SECOND = 4294967295L const val CORRUPTED_TIMESTAMP_IN_MILLISECOND = 4294967295000L @JvmField val USER_AGENT = "eos(" + buildTime + ")-eDrive(" + BuildConfig.VERSION_NAME + ")" Loading
app/src/test/java/foundation/e/drive/periodicScan/contentScanner/FileDiffUtilsTest.kt +6 −5 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ package foundation.e.drive.periodicScan.contentScanner import com.owncloud.android.lib.resources.files.model.RemoteFile import foundation.e.drive.models.SyncedFileState import foundation.e.drive.periodicScan.contentScanner.FileDiffUtils import foundation.e.drive.utils.AppConstants import org.junit.Assert import org.junit.Test import org.mockito.Mockito Loading Loading @@ -294,21 +295,21 @@ internal class FileDiffUtilsTest { /* isCorruptedTimestamp for localFile */ @Test fun `isCorruptedTimestamp() return true with timestamp equal to max of Int32 `() { val corruptedTimestamp = 4294967295L val corruptedTimestamp = AppConstants.CORRUPTED_TIMESTAMP_IN_MILLISECOND val resultUnderTest = FileDiffUtils.isCorruptedTimestamp(corruptedTimestamp) Assert.assertTrue("isCorruptedTimestamp(4294967295L) returned $resultUnderTest instead of true", resultUnderTest) Assert.assertTrue("isCorruptedTimestamp(4294967295000L) returned $resultUnderTest instead of true", resultUnderTest) } @Test fun `isCorruptedTimestamp() return true with timestamp bigger than max of Int32 `() { val corruptedTimestamp = 4294967295L + 1 val corruptedTimestamp = AppConstants.CORRUPTED_TIMESTAMP_IN_MILLISECOND + 1 val resultUnderTest = FileDiffUtils.isCorruptedTimestamp(corruptedTimestamp) Assert.assertTrue("isCorruptedTimestamp(4294967295L) returned $resultUnderTest instead of true", resultUnderTest) Assert.assertTrue("isCorruptedTimestamp(4294967295000L) returned $resultUnderTest instead of true", resultUnderTest) } @Test fun `isCorruptedTimestamp() return false with timestamp smaller than max of Int32 `() { val corruptedTimestamp = 4294967295L - 1 val corruptedTimestamp = AppConstants.CORRUPTED_TIMESTAMP_IN_MILLISECOND - 1 val resultUnderTest = FileDiffUtils.isCorruptedTimestamp(corruptedTimestamp) Assert.assertFalse("isCorruptedTimestamp(4294967295000L) returned $resultUnderTest instead of false", resultUnderTest) } Loading