Skip to content

Commit 0e7c557

Browse files
committed
fix: auto upload file skip check
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent dc8025f commit 0e7c557

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

app/src/main/java/com/nextcloud/client/jobs/autoUpload/FileSystemRepository.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,19 @@ class FileSystemRepository(private val dao: FileSystemDao, private val context:
159159
return
160160
}
161161

162+
val entity = dao.getFileByPathAndFolder(localPath, syncedFolder.id.toString())
163+
val fileSentForUpload = (entity != null && entity.fileSentForUpload == 1)
164+
if (fileSentForUpload) {
165+
Log_OC.d(TAG, "File was sent for upload, checking if it changed...")
166+
}
167+
162168
val fileModified = (lastModified ?: file.lastModified())
163-
val shouldSkipFileBasedOnFolderSettings = syncedFolder.shouldSkipFile(file, fileModified, creationTime)
164-
if (shouldSkipFileBasedOnFolderSettings) {
169+
if (syncedFolder.shouldSkipFile(file, fileModified, creationTime, fileSentForUpload)) {
165170
return
166171
}
167172

168-
val entity = dao.getFileByPathAndFolder(localPath, syncedFolder.id.toString())
169-
if (entity != null && entity.fileSentForUpload == 1) {
170-
Log_OC.w(
171-
TAG,
172-
"file already uploaded path: $localPath, " +
173-
"syncedFolder: ${syncedFolder.localPath}, ${syncedFolder.id}"
174-
)
175-
return
173+
if (fileSentForUpload) {
174+
Log_OC.d(TAG, "File was sent for upload before but has changed, will re-upload: $localPath")
176175
}
177176

178177
val crc = getFileChecksum(file)
@@ -182,7 +181,7 @@ class FileSystemRepository(private val dao: FileSystemDao, private val context:
182181
localPath = localPath,
183182
fileIsFolder = if (file.isDirectory) 1 else 0,
184183
fileFoundRecently = System.currentTimeMillis(),
185-
fileSentForUpload = 0,
184+
fileSentForUpload = 0, // Reset to 0 to queue for upload
186185
syncedFolderId = syncedFolder.id.toString(),
187186
crc32 = crc?.toString(),
188187
fileModified = fileModified

app/src/main/java/com/nextcloud/utils/extensions/SyncedFolderExtensions.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ private const val TAG = "SyncedFolderExtensions"
2222
* Determines whether a file should be skipped during auto-upload based on folder settings.
2323
*/
2424
@Suppress("ReturnCount")
25-
fun SyncedFolder.shouldSkipFile(file: File, lastModified: Long, creationTime: Long?): Boolean {
25+
fun SyncedFolder.shouldSkipFile(
26+
file: File,
27+
lastModified: Long,
28+
creationTime: Long?,
29+
fileSentForUpload: Boolean
30+
): Boolean {
2631
Log_OC.d(TAG, "Checking file: ${file.name}, lastModified=$lastModified, lastScan=$lastScanTimestampMs")
2732

2833
if (isExcludeHidden && file.isHidden) {
@@ -38,15 +43,19 @@ fun SyncedFolder.shouldSkipFile(file: File, lastModified: Long, creationTime: Lo
3843
return true
3944
}
4045
} else {
41-
Log_OC.w(TAG, "file sent for upload - cannot determine creation time: ${file.absolutePath}")
46+
Log_OC.w(TAG, "file will be inserted to db - cannot determine creation time: ${file.absolutePath}")
4247
return false
4348
}
4449
}
4550

46-
// Skip files that haven't changed since last scan (already processed)
47-
// BUT only if this is not the first scan
48-
if (lastScanTimestampMs != -1L && lastModified < lastScanTimestampMs) {
49-
Log_OC.d(TAG, "Skipping unchanged file (last modified < last scan): ${file.absolutePath}")
51+
// Skip files that haven't changed since last scan ONLY if they were sent for upload
52+
// AND only if this is not the first scan
53+
if (fileSentForUpload && lastScanTimestampMs != -1L && lastModified < lastScanTimestampMs) {
54+
Log_OC.d(
55+
TAG,
56+
"Skipping unchanged file that was already sent for upload (last modified < last scan): " +
57+
"${file.absolutePath}"
58+
)
5059
return true
5160
}
5261

0 commit comments

Comments
 (0)