-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix conflicts for offline uploads when uploading same file again #17590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8d7dfdb
98f7dcd
6b641b8
5896d05
21d2439
085327f
b2a8db6
c652512
0c44112
180c0cf
0c3ffbd
a43c25e
ee23509
46aaf24
a6ab15a
0c93a95
870ec84
6de6620
52dbfa4
e876e22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,16 +8,22 @@ | |
| package com.nextcloud.utils.extensions | ||
|
|
||
| import android.graphics.Bitmap | ||
| import android.util.Log | ||
| import androidx.exifinterface.media.ExifInterface | ||
| 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 | ||
| import com.owncloud.android.lib.resources.files.model.ServerFileInterface | ||
| import com.owncloud.android.utils.DisplayUtils | ||
| import java.io.File | ||
| import java.io.IOException | ||
| import java.nio.file.Files | ||
| import java.nio.file.Path | ||
| import java.nio.file.attribute.BasicFileAttributes | ||
|
|
||
| private const val TAG = "FileExtensions" | ||
| private const val MS_IN_SECOND = 1000 | ||
|
|
||
| fun OCFile?.logFileSize(tag: String) { | ||
| val size = DisplayUtils.bytesToHumanReadable(this?.fileLength ?: -1) | ||
|
|
@@ -111,3 +117,25 @@ fun String.getBitmapSize(): Pair<Int, Int>? = try { | |
| } catch (_: Exception) { | ||
| null | ||
| } | ||
|
|
||
| fun OCFile?.isTheSameAs(localFile: File?): Boolean = try { | ||
| this ?: return false | ||
| localFile ?: return false | ||
|
|
||
| val attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes::class.java) | ||
| val localName = localFile.getName() | ||
| val remoteName = this.fileName | ||
| val localSize = localFile.length() | ||
| val remoteSize = this.fileLength | ||
| val localCreated = attr.creationTime().toMillis() / MS_IN_SECOND // Unix time in milliseconds | ||
| val localModified = attr.lastModifiedTime().toMillis() / MS_IN_SECOND // Unix time in milliseconds | ||
| val remoteCreated = this.creationTimestamp // Unix time in seconds! | ||
| val remoteModified = this.modificationTimestamp / MS_IN_SECOND // Unix time in milliseconds | ||
| remoteName == localName && | ||
| remoteSize == localSize && | ||
| remoteCreated == localCreated && | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come Scenario 1: File created from other client, remote creating date written in the server's DB and Android client writes that and compare against the potentially exists local file this can be same file but creating time can be different. Scenario 2: File created from Android client does server stores Android's creation time exactly or stores based on server's creation time?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. Not sure about this, i looked into it with the debugger:
I checked why remoteCreated isn't populated: it is, but it's already 0 in RemoteFile
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was the created from other client same? |
||
| remoteModified == localModified | ||
| } catch (e: IOException) { | ||
| Log.e(FileDataStorageManager.TAG, "fileIsTheSame: unable to obtain local file attributes for comparing: $e") | ||
| false | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val regex = Regex("""(.*)\((\d+)\)$""", RegexOption.MULTILINE)Can we move out of the function thus no need to create every time again?