Skip to content

Commit

Permalink
Merge pull request nextcloud#14438 from nextcloud/revert-auto-upload-…
Browse files Browse the repository at this point in the history
…scan-logic

Revert Get Files For Auto Upload
  • Loading branch information
tobiasKaminsky authored Jan 21, 2025
2 parents d8de726 + dc0de74 commit f953f52
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 21 deletions.
34 changes: 13 additions & 21 deletions app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import com.owncloud.android.utils.FileStorageUtils
import com.owncloud.android.utils.FilesSyncHelper
import com.owncloud.android.utils.MimeType
import com.owncloud.android.utils.MimeTypeUtil
import com.owncloud.android.utils.SyncedFolderUtils.isFileNameQualifiedForAutoUpload
import com.owncloud.android.utils.SyncedFolderUtils.isQualifiedFolder
import java.io.File
import java.text.ParsePosition
import java.text.SimpleDateFormat
Expand Down Expand Up @@ -218,20 +216,6 @@ class FilesSyncWork(
syncedFolderProvider.updateSyncFolder(syncedFolder)
}

private fun getAllFiles(path: String): Set<File> {
return File(path).takeIf { it.exists() }
?.walkTopDown()
?.asSequence()
?.filter { file ->
file.isFile &&
file.exists() &&
isQualifiedFolder(file.parentFile?.path) &&
isFileNameQualifiedForAutoUpload(file.name)
}
?.toSet()
?: emptySet()
}

@Suppress("LongMethod") // legacy code
private fun uploadFilesFromFolder(
context: Context,
Expand Down Expand Up @@ -259,12 +243,20 @@ class FilesSyncWork(
null
}

val files = getAllFiles(syncedFolder.localPath)
if (files.isEmpty()) {
// Ensure only new files are processed for upload.
// Files that have been previously uploaded cannot be re-uploaded,
// even if they have been deleted or moved from the target folder,
// as they are already marked as uploaded in the database.
val paths = filesystemDataProvider.getFilesForUpload(
syncedFolder.localPath,
syncedFolder.id.toString()
)
if (paths.isEmpty()) {
return
}

val pathsAndMimes = files.map { file ->
val pathsAndMimes = paths.map { path ->
val file = File(path)
val localPath = file.absolutePath
Triple(
localPath,
Expand Down Expand Up @@ -304,9 +296,9 @@ class FilesSyncWork(
syncedFolder.nameCollisionPolicy
)

for (file in files) {
for (path in paths) {
filesystemDataProvider.updateFilesystemFileAsSentForUpload(
file.path,
path,
syncedFolder.id.toString()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@

import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.utils.SyncedFolderUtils;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;
import java.util.zip.CRC32;

/**
Expand Down Expand Up @@ -113,6 +117,49 @@ public void storeOrUpdateFileValue(String localPath, long modifiedAt, boolean is
}
}

public Set<String> getFilesForUpload(String localPath, String syncedFolderId) {
Set<String> localPathsToUpload = new HashSet<>();

String likeParam = localPath + "%";

Cursor cursor = contentResolver.query(
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
null,
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH + " LIKE ? and " +
ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " = ? and " +
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD + " = ? and " +
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER + " = ?",
new String[]{likeParam, syncedFolderId, "0", "0"},
null);

if (cursor != null) {
if (cursor.moveToFirst()) {
do {
String value = cursor.getString(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH));
if (value == null) {
Log_OC.e(TAG, "Cannot get local path");
} else {
File file = new File(value);
if (!file.exists()) {
Log_OC.d(TAG, "Ignoring file for upload (doesn't exist): " + value);
} else if (!SyncedFolderUtils.isQualifiedFolder(file.getParent())) {
Log_OC.d(TAG, "Ignoring file for upload (unqualified folder): " + value);
} else if (!SyncedFolderUtils.isFileNameQualifiedForAutoUpload(file.getName())) {
Log_OC.d(TAG, "Ignoring file for upload (unqualified file): " + value);
} else {
localPathsToUpload.add(value);
}
}
} while (cursor.moveToNext());
}

cursor.close();
}

return localPathsToUpload;
}

private FileSystemDataSet getFilesystemDataSet(String localPathParam, SyncedFolder syncedFolder) {

Cursor cursor = contentResolver.query(
Expand Down

0 comments on commit f953f52

Please sign in to comment.