Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.nextcloud.client.device.BatteryStatus
import com.nextcloud.client.device.PowerManagementService
import com.nextcloud.client.di.ApplicationScope
import com.nextcloud.client.jobs.BackgroundJobManager
import com.nextcloud.client.jobs.upload.FileUploadHelper.Companion.MAX_UPLOADS_PER_QUERY
import com.nextcloud.client.network.Connectivity
import com.nextcloud.client.network.ConnectivityService
import com.nextcloud.client.notifications.AppWideNotificationManager
Expand Down Expand Up @@ -599,13 +600,18 @@ class FileUploadHelper {

@Suppress("MagicNumber", "ReturnCount", "ComplexCondition")
fun isSameFileOnRemote(user: User?, localPath: String?, remotePath: String?, context: Context?): Boolean {
Log_OC.d(
"105127",
"isSameFileOnRemote user:[$user], localPath:[$localPath], remotePath:[$remotePath], context:[$context]"
)
if (user == null || localPath == null || remotePath == null || context == null) {
Log_OC.e(TAG, "cannot compare remote and local file")
return false
}

val operation = ReadFileRemoteOperation(remotePath)
val result: RemoteOperationResult<*> = operation.execute(user, context)
Log_OC.d("105127", "isSameFileOnRemote result:[${result.isSuccess}]")
if (result.isSuccess) {
val remoteFile = result.data[0] as RemoteFile
return remoteFile.isSame(localPath)
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/com/nextcloud/utils/extensions/FileExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import android.graphics.Bitmap
import android.util.Log
import androidx.exifinterface.media.ExifInterface
import com.nextcloud.utils.HumanReadableFormatter
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.datamodel.ThumbnailsCacheManager
import com.owncloud.android.lib.common.utils.Log_OC
Expand Down Expand Up @@ -131,10 +130,18 @@ fun OCFile?.isTheSameAs(localFile: File?): Boolean = try {
val remoteSize = this.fileLength
val localModified = attr.lastModifiedTime().toMillis() / MS_IN_SECOND // Unix time in milliseconds
val remoteModified = this.modificationTimestamp / MS_IN_SECOND // Unix time in milliseconds
remoteName == localName &&
val isTheSame = remoteName == localName &&
remoteSize == localSize &&
remoteModified == localModified

Log_OC.d(
"105127",
"OCFileIsTheSameAs field:[local|remote] -> name:[$localName|$remoteName], " +
"size:[$localSize|$remoteSize], modified:[$localModified|$remoteModified], isTheSame:$isTheSame"
)

isTheSame
} catch (e: IOException) {
Log.e(FileDataStorageManager.TAG, "fileIsTheSame: unable to obtain local file attributes for comparing: $e")
Log.e("105127", "OCFileIsTheSameAs fileIsTheSame: unable to obtain local file attributes for comparing: $e")
false
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.nextcloud.utils.extensions

import com.nextcloud.utils.TimeConstants
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.resources.files.model.RemoteFile
import com.owncloud.android.lib.resources.shares.ShareeUser
import com.owncloud.android.lib.resources.tags.Tag
Expand All @@ -24,11 +25,21 @@ fun RemoteFile.isSame(path: String?): Boolean {
val localCreationTimestamp = FileUtil.getCreationTimestamp(localFile)
val localSize: Long = localFile.length()

return size == localSize &&
val isTheSame = size == localSize &&
localCreationTimestamp != null &&
localCreationTimestamp == creationTimestamp &&
modifiedTimestamp == localLastModifiedTimestamp * TimeConstants.MILLIS_PER_SECOND &&
this.areImageDimensionsSame(path)

Log_OC.d(
"105127",
"RemoteFileIsSame field:[local|remote] -> size:[$localSize|$size], " +
"creation:[$localCreationTimestamp|$creationTimestamp], " +
"modif:[${localLastModifiedTimestamp * TimeConstants.MILLIS_PER_SECOND}|$modifiedTimestamp], " +
"areImageDimensionsSame: [${this.areImageDimensionsSame(path)}], isTheSame:[$isTheSame]"
)

return isTheSame
}

fun RemoteFile.sharedViaLink(): Boolean = sharees?.any { it.shareType?.isLink == true } ?: false
Expand Down Expand Up @@ -62,6 +73,16 @@ private fun RemoteFile.areImageDimensionsSame(path: String): Boolean {
return true
}

return localFileImageDimension.first.toFloat() == imageDimension?.width &&
val dimAreTheSame = localFileImageDimension.first.toFloat() == imageDimension?.width &&
localFileImageDimension.second.toFloat() == imageDimension?.height

Log_OC.d(
"105127",
"areImageDimensionsSame field:[local|remote] -> " +
"width:[${localFileImageDimension.first.toFloat()}|${imageDimension?.width}], " +
"width:[${localFileImageDimension.second.toFloat()}|${imageDimension?.height}]," +
"dimAreTheSame:[$dimAreTheSame]"
)

return dimAreTheSame
}
Loading