mirror of
https://github.com/nextcloud/android.git
synced 2024-12-18 15:01:57 +03:00
Merge pull request #14161 from nextcloud/bugfix/get-files-for-upload
BugFix - Get Files For Auto Upload
This commit is contained in:
commit
9f7370f76b
2 changed files with 29 additions and 63 deletions
|
@ -23,7 +23,6 @@ import com.nextcloud.client.jobs.upload.FileUploadWorker
|
||||||
import com.nextcloud.client.network.ConnectivityService
|
import com.nextcloud.client.network.ConnectivityService
|
||||||
import com.nextcloud.client.preferences.SubFolderRule
|
import com.nextcloud.client.preferences.SubFolderRule
|
||||||
import com.owncloud.android.R
|
import com.owncloud.android.R
|
||||||
import com.owncloud.android.datamodel.ArbitraryDataProvider
|
|
||||||
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
|
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
|
||||||
import com.owncloud.android.datamodel.FilesystemDataProvider
|
import com.owncloud.android.datamodel.FilesystemDataProvider
|
||||||
import com.owncloud.android.datamodel.MediaFolderType
|
import com.owncloud.android.datamodel.MediaFolderType
|
||||||
|
@ -37,6 +36,8 @@ import com.owncloud.android.utils.FileStorageUtils
|
||||||
import com.owncloud.android.utils.FilesSyncHelper
|
import com.owncloud.android.utils.FilesSyncHelper
|
||||||
import com.owncloud.android.utils.MimeType
|
import com.owncloud.android.utils.MimeType
|
||||||
import com.owncloud.android.utils.MimeTypeUtil
|
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.io.File
|
||||||
import java.text.ParsePosition
|
import java.text.ParsePosition
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
|
@ -217,6 +218,20 @@ class FilesSyncWork(
|
||||||
syncedFolderProvider.updateSyncFolder(syncedFolder)
|
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
|
@Suppress("LongMethod") // legacy code
|
||||||
private fun uploadFilesFromFolder(
|
private fun uploadFilesFromFolder(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
@ -230,29 +245,26 @@ class FilesSyncWork(
|
||||||
val uploadAction: Int?
|
val uploadAction: Int?
|
||||||
val needsCharging: Boolean
|
val needsCharging: Boolean
|
||||||
val needsWifi: Boolean
|
val needsWifi: Boolean
|
||||||
var file: File
|
|
||||||
val accountName = syncedFolder.account
|
val accountName = syncedFolder.account
|
||||||
|
|
||||||
val optionalUser = userAccountManager.getUser(accountName)
|
val optionalUser = userAccountManager.getUser(accountName)
|
||||||
if (!optionalUser.isPresent) {
|
if (!optionalUser.isPresent) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val user = optionalUser.get()
|
val user = optionalUser.get()
|
||||||
val arbitraryDataProvider: ArbitraryDataProvider? = if (lightVersion) {
|
val arbitraryDataProvider = if (lightVersion) {
|
||||||
ArbitraryDataProviderImpl(context)
|
ArbitraryDataProviderImpl(context)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
val paths = filesystemDataProvider.getFilesForUpload(
|
|
||||||
syncedFolder.localPath,
|
|
||||||
syncedFolder.id.toString()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (paths.size == 0) {
|
val files = getAllFiles(syncedFolder.localPath)
|
||||||
|
if (files.isEmpty()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val pathsAndMimes = paths.map { path ->
|
val pathsAndMimes = files.map { file ->
|
||||||
file = File(path)
|
|
||||||
val localPath = file.absolutePath
|
val localPath = file.absolutePath
|
||||||
Triple(
|
Triple(
|
||||||
localPath,
|
localPath,
|
||||||
|
@ -260,15 +272,17 @@ class FilesSyncWork(
|
||||||
MimeTypeUtil.getBestMimeTypeByFilename(localPath)
|
MimeTypeUtil.getBestMimeTypeByFilename(localPath)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val localPaths = pathsAndMimes.map { it.first }.toTypedArray()
|
val localPaths = pathsAndMimes.map { it.first }.toTypedArray()
|
||||||
val remotePaths = pathsAndMimes.map { it.second }.toTypedArray()
|
val remotePaths = pathsAndMimes.map { it.second }.toTypedArray()
|
||||||
|
|
||||||
if (lightVersion) {
|
if (lightVersion) {
|
||||||
needsCharging = resources.getBoolean(R.bool.syncedFolder_light_on_charging)
|
needsCharging = resources.getBoolean(R.bool.syncedFolder_light_on_charging)
|
||||||
needsWifi = arbitraryDataProvider!!.getBooleanValue(
|
needsWifi = arbitraryDataProvider?.getBooleanValue(
|
||||||
accountName,
|
accountName,
|
||||||
SettingsActivity.SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI
|
SettingsActivity.SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI
|
||||||
)
|
) ?: true
|
||||||
|
|
||||||
val uploadActionString = resources.getString(R.string.syncedFolder_light_upload_behaviour)
|
val uploadActionString = resources.getString(R.string.syncedFolder_light_upload_behaviour)
|
||||||
uploadAction = getUploadAction(uploadActionString)
|
uploadAction = getUploadAction(uploadActionString)
|
||||||
} else {
|
} else {
|
||||||
|
@ -276,6 +290,7 @@ class FilesSyncWork(
|
||||||
needsWifi = syncedFolder.isWifiOnly
|
needsWifi = syncedFolder.isWifiOnly
|
||||||
uploadAction = syncedFolder.uploadAction
|
uploadAction = syncedFolder.uploadAction
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUploadHelper.instance().uploadNewFiles(
|
FileUploadHelper.instance().uploadNewFiles(
|
||||||
user,
|
user,
|
||||||
localPaths,
|
localPaths,
|
||||||
|
@ -289,10 +304,9 @@ class FilesSyncWork(
|
||||||
syncedFolder.nameCollisionPolicy
|
syncedFolder.nameCollisionPolicy
|
||||||
)
|
)
|
||||||
|
|
||||||
for (path in paths) {
|
for (file in files) {
|
||||||
// TODO batch update
|
|
||||||
filesystemDataProvider.updateFilesystemFileAsSentForUpload(
|
filesystemDataProvider.updateFilesystemFileAsSentForUpload(
|
||||||
path,
|
file.path,
|
||||||
syncedFolder.id.toString()
|
syncedFolder.id.toString()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,16 +14,11 @@ import android.net.Uri;
|
||||||
|
|
||||||
import com.owncloud.android.db.ProviderMeta;
|
import com.owncloud.android.db.ProviderMeta;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import com.owncloud.android.utils.SyncedFolderUtils;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.zip.CRC32;
|
import java.util.zip.CRC32;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,49 +58,6 @@ public class FilesystemDataProvider {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void storeOrUpdateFileValue(String localPath, long modifiedAt, boolean isFolder, SyncedFolder syncedFolder) {
|
public void storeOrUpdateFileValue(String localPath, long modifiedAt, boolean isFolder, SyncedFolder syncedFolder) {
|
||||||
|
|
||||||
// takes multiple milliseconds to query data from database (around 75% of execution time) (6ms)
|
// takes multiple milliseconds to query data from database (around 75% of execution time) (6ms)
|
||||||
|
|
Loading…
Reference in a new issue