@@ -9,7 +9,6 @@ package com.owncloud.android.ui.asynctasks
99import android.content.ContentResolver
1010import android.content.Context
1111import android.net.Uri
12- import android.provider.DocumentsContract
1312import android.widget.Toast
1413import com.nextcloud.client.account.User
1514import com.nextcloud.client.jobs.upload.FileUploadHelper
@@ -65,11 +64,12 @@ class CopyAndUploadContentUrisTask(
6564 val localPaths = arrayOfNulls<String >(sourceUris.size)
6665 val resolvedRemotePaths = arrayOfNulls<String >(sourceUris.size)
6766 var currentTempPath: String? = null
67+ val lastModifiedResolver = ContentUriLastModifiedResolver (contentResolver)
6868
6969 return try {
7070 sourceUris.forEachIndexed { index, uri ->
7171 val remotePath = remotePaths[index]
72- val lastModified = queryLastModified(contentResolver, uri)
72+ val lastModified = lastModifiedResolver.resolve( uri)
7373
7474 currentTempPath = " ${FileStorageUtils .getTemporalPath(user.accountName)}$remotePath "
7575 val cacheFile = File (currentTempPath)
@@ -129,18 +129,11 @@ class CopyAndUploadContentUrisTask(
129129 }
130130 }
131131
132- private fun queryLastModified (contentResolver : ContentResolver , uri : Uri ): Long = runCatching {
133- contentResolver.query(uri, null , null , null , null )?.use { cursor ->
134- if (! cursor.moveToFirst()) return @use 0L
135- val col = cursor.getColumnIndex(DocumentsContract .Document .COLUMN_LAST_MODIFIED )
136- if (col >= 0 ) cursor.getLong(col) else 0L
137- } ? : 0L
138- }.getOrDefault(0L )
139-
140132 private fun applyLastModified (file : File , lastModified : Long ) {
141- if (lastModified == 0L ) return
142- runCatching { file.setLastModified(lastModified) }
143- .onFailure { Log_OC .w(TAG , " Could not set lastModified on cache file: ${it.message} " ) }
133+ if (lastModified <= 0L ) return
134+ if (! file.setLastModified(lastModified)) {
135+ Log_OC .w(TAG , " Could not set lastModified on cache file: ${file.path} " )
136+ }
144137 }
145138
146139 private fun dispatchResult (result : ResultCode ) {
0 commit comments