Skip to content
Open
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 @@ -66,6 +66,7 @@ import com.infomaniak.drive.data.models.upload.UploadSession.StartUploadSession
import com.infomaniak.drive.data.models.upload.ValidChunks
import com.infomaniak.drive.utils.AccountUtils
import okhttp3.OkHttpClient
import java.util.Date
import com.infomaniak.core.auth.networking.HttpClient.okHttpClientLongTimeoutWithTokenInterceptor as okHttpClientLongTimeout
import com.infomaniak.core.ksuite.myksuite.ui.network.ApiRoutes as MyKSuiteApiRoutes

Expand Down Expand Up @@ -242,7 +243,7 @@ object ApiRepository : ApiRepositoryCore() {
conflictOption = ConflictOption.RENAME,
directoryPath = remoteSubFolder,
createdAt = uploadFile.fileCreatedAt,
lastModifiedAt = uploadFile.fileModifiedAt,
lastModifiedAt = Date(uploadFile.getLastModified()),
Comment thread
tevincent marked this conversation as resolved.
)

ApiController.callApi<ApiResponse<File>>(uploadUrl, POST)
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/com/infomaniak/drive/data/api/UploadTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import splitties.experimental.ExperimentalSplittiesApi
import java.io.FileNotFoundException
import java.io.IOException
import java.io.InputStream
import java.util.Date
import kotlin.concurrent.atomics.AtomicLong
import kotlin.concurrent.atomics.ExperimentalAtomicApi
import kotlin.concurrent.atomics.minusAssign
Expand Down Expand Up @@ -170,7 +171,7 @@ class UploadTask(
fileSize = uploadFile.fileSize,
conflictOption = uploadFile.uploadConflictOption(),
createdAt = uploadFile.fileCreatedAt,
lastModifiedAt = uploadFile.fileModifiedAt,
lastModifiedAt = Date(uploadFile.getLastModified()),
)
uploadChunkUnchecked(inputStream, httpClient, url = url, length = uploadFile.fileSize)
}
Expand Down Expand Up @@ -459,14 +460,12 @@ class UploadTask(
}

private fun UploadFile.prepareUploadSession(totalChunks: Int): String? {
val currentTimeMillis = System.currentTimeMillis()
val lastModifiedAt = if (fileModifiedAt.time > currentTimeMillis) currentTimeMillis else fileModifiedAt.time
val sessionBody = UploadSession.StartSessionBody(
conflict = uploadConflictOption(),
createdAt = if (fileCreatedAt == null) null else fileCreatedAt!!.time / 1_000L,
directoryId = remoteFolder,
fileName = fileName,
lastModifiedAt = lastModifiedAt / 1_000L,
lastModifiedAt = getLastModified() / 1_000L,
subDirectoryPath = remoteSubFolder ?: "",
totalChunks = totalChunks,
totalSize = fileSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ open class UploadFile(
fun isSchemeFile() = getUriObject().scheme.equals(ContentResolver.SCHEME_FILE)

fun createSubFolder(parent: String, createDatedSubFolders: Boolean) {
remoteSubFolder = parent + if (createDatedSubFolders) "/${fileModifiedAt.format("yyyy/MM")}" else ""
remoteSubFolder = parent + if (createDatedSubFolders) "/${Date(getLastModified()).format("yyyy/MM")}" else ""
Comment thread
tevincent marked this conversation as resolved.
}

fun store(coroutineContext: CoroutineContext = EmptyCoroutineContext, customRealm: Realm? = null) {
Expand Down Expand Up @@ -154,6 +154,12 @@ open class UploadFile(
}
}

fun getLastModified(): Long {
val currentTimeMillis = System.currentTimeMillis()
val lastModifiedAt = if (fileModifiedAt.time > currentTimeMillis) currentTimeMillis else fileModifiedAt.time
return lastModifiedAt
}

Comment thread
tevincent marked this conversation as resolved.
private fun deleteIfExistsInternal(keepFile: Boolean = false, realm: Realm) {
val uploadFileProxy = uploadFileByUriQuery(realm, uri).findFirst() ?: return
// Cancel session if exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class UploadWorker(appContext: Context, params: WorkerParameters) : CoroutineWor
deleteIfExists(keepFile = isSync())

// If is an ACTION_OPEN_DOCUMENT exception and the file is older than August 17, 2022 we ignore sentry
if (fileModifiedAt < Date(1660736262000) && exception.message?.contains("ACTION_OPEN_DOCUMENT") == true) return
if (Date(getLastModified()) < Date(1660736262000) && exception.message?.contains("ACTION_OPEN_DOCUMENT") == true) return
Comment thread
tevincent marked this conversation as resolved.

if (exception !is IllegalStateException) Sentry.captureException(exception)
}
Expand Down
Loading