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 @@ -159,20 +159,19 @@ class FileSystemRepository(private val dao: FileSystemDao, private val context:
return
}

val entity = dao.getFileByPathAndFolder(localPath, syncedFolder.id.toString())
val fileSentForUpload = (entity != null && entity.fileSentForUpload == 1)
if (fileSentForUpload) {
Log_OC.d(TAG, "File was sent for upload, checking if it changed...")
}

val fileModified = (lastModified ?: file.lastModified())
val shouldSkipFileBasedOnFolderSettings = syncedFolder.shouldSkipFile(file, fileModified, creationTime)
if (shouldSkipFileBasedOnFolderSettings) {
if (syncedFolder.shouldSkipFile(file, fileModified, creationTime, fileSentForUpload)) {
return
}

val entity = dao.getFileByPathAndFolder(localPath, syncedFolder.id.toString())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAutoUploadFilesEntities already returns file needs to be uploaded and if we skip when fileSentForUpload is true, changed files will not be uploaded.

if (entity != null && entity.fileSentForUpload == 1) {
Log_OC.w(
TAG,
"file already uploaded path: $localPath, " +
"syncedFolder: ${syncedFolder.localPath}, ${syncedFolder.id}"
)
return
if (fileSentForUpload) {
Log_OC.d(TAG, "File was sent for upload before but has changed, will re-upload: $localPath")
}

val crc = getFileChecksum(file)
Expand All @@ -182,7 +181,7 @@ class FileSystemRepository(private val dao: FileSystemDao, private val context:
localPath = localPath,
fileIsFolder = if (file.isDirectory) 1 else 0,
fileFoundRecently = System.currentTimeMillis(),
fileSentForUpload = 0,
fileSentForUpload = 0, // Reset to 0 to queue for upload
syncedFolderId = syncedFolder.id.toString(),
crc32 = crc?.toString(),
fileModified = fileModified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ private const val TAG = "SyncedFolderExtensions"
* Determines whether a file should be skipped during auto-upload based on folder settings.
*/
@Suppress("ReturnCount")
fun SyncedFolder.shouldSkipFile(file: File, lastModified: Long, creationTime: Long?): Boolean {
fun SyncedFolder.shouldSkipFile(
file: File,
lastModified: Long,
creationTime: Long?,
fileSentForUpload: Boolean
): Boolean {
Log_OC.d(TAG, "Checking file: ${file.name}, lastModified=$lastModified, lastScan=$lastScanTimestampMs")

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

// Skip files that haven't changed since last scan (already processed)
// BUT only if this is not the first scan
if (lastScanTimestampMs != -1L && lastModified < lastScanTimestampMs) {
Log_OC.d(TAG, "Skipping unchanged file (last modified < last scan): ${file.absolutePath}")
// Skip files that haven't changed since last scan ONLY if they were sent for upload
// AND only if this is not the first scan
if (fileSentForUpload && lastScanTimestampMs != -1L && lastModified < lastScanTimestampMs) {
Log_OC.d(
TAG,
"Skipping unchanged file that was already sent for upload (last modified < last scan): " +
"${file.absolutePath}"
)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ class AutoUploadHelperTest {
type = MediaFolderType.CUSTOM
)

val shouldSkipOldFile = folder.shouldSkipFile(oldFile, oldFileLastModified, null)
val shouldSkipOldFile = folder.shouldSkipFile(oldFile, oldFileLastModified, null, true)
assertTrue(shouldSkipOldFile)

val shouldSkipNewFile = folder.shouldSkipFile(newFile, currentTime, null)
val shouldSkipNewFile = folder.shouldSkipFile(newFile, currentTime, null, false)
assertTrue(!shouldSkipNewFile)
}

Expand All @@ -157,10 +157,10 @@ class AutoUploadHelperTest {
lastScanTimestampMs = currentTime
}

val shouldSkipOldFile = folder.shouldSkipFile(oldFile, oldFileLastModified, null)
val shouldSkipOldFile = folder.shouldSkipFile(oldFile, oldFileLastModified, null, true)
assertTrue(shouldSkipOldFile)

val shouldSkipNewFile = folder.shouldSkipFile(newFile, currentTime, null)
val shouldSkipNewFile = folder.shouldSkipFile(newFile, currentTime, null, false)
assertTrue(!shouldSkipNewFile)
}

Expand Down Expand Up @@ -305,10 +305,10 @@ class AutoUploadHelperTest {
setEnabled(true, currentTime)
}

val shouldSkipOldFile = folderSkipOld.shouldSkipFile(oldFile, oldFileLastModified, oldFileCreationTime)
val shouldSkipOldFile = folderSkipOld.shouldSkipFile(oldFile, oldFileLastModified, oldFileCreationTime, true)
assertTrue(shouldSkipOldFile)

val shouldSkipNewFile = folderSkipOld.shouldSkipFile(newFile, newFileLastModified, newFileCreationTime)
val shouldSkipNewFile = folderSkipOld.shouldSkipFile(newFile, newFileLastModified, newFileCreationTime, false)
assertTrue(!shouldSkipNewFile)

val folderUploadAll = createTestFolder(
Expand All @@ -320,11 +320,11 @@ class AutoUploadHelperTest {
}

val shouldSkipOldFileIfAlsoUploadExistingFile =
folderUploadAll.shouldSkipFile(oldFile, oldFileLastModified, oldFileCreationTime)
folderUploadAll.shouldSkipFile(oldFile, oldFileLastModified, oldFileCreationTime, true)
assertTrue(!shouldSkipOldFileIfAlsoUploadExistingFile)

val shouldSkipNewFileIfAlsoUploadExistingFile =
folderUploadAll.shouldSkipFile(newFile, newFileLastModified, newFileCreationTime)
folderUploadAll.shouldSkipFile(newFile, newFileLastModified, newFileCreationTime, false)
assertTrue(!shouldSkipNewFileIfAlsoUploadExistingFile)
}
}
Loading