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 @@ -17,6 +17,16 @@ import com.owncloud.android.db.ProviderMeta

@Dao
interface FileSystemDao {
@Query(
"""
SELECT COUNT(*) > 0 FROM ${ProviderMeta.ProviderTableMeta.FILESYSTEM_TABLE_NAME}
WHERE ${ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH} = :localPath
AND ${ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID} IS NOT NULL
LIMIT 1
"""
)
suspend fun isBelongToAnyAutoFolder(localPath: String): Boolean

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertOrReplace(filesystemEntity: FilesystemEntity)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ class BackgroundJobFactory @Inject constructor(
localBroadcastManager.get(),
backgroundJobManager.get(),
preferences,
FileSystemRepository(dao = database.fileSystemDao(), uploadsStorageManager, context),
syncedFolderProvider,
context,
params
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class FileSystemRepository(
const val BATCH_SIZE = 50
}

suspend fun isBelongToAnyAutoFolder(localPath: String): Boolean = dao.isBelongToAnyAutoFolder(localPath)

fun deleteAutoUploadAndUploadEntity(syncedFolder: SyncedFolder, localPath: String, entity: FilesystemEntity) {
Log_OC.d(TAG, "deleting auto upload entity and upload entity")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.client.device.PowerManagementService
import com.nextcloud.client.jobs.BackgroundJobManager
import com.nextcloud.client.jobs.BackgroundJobManagerImpl
import com.nextcloud.client.jobs.autoUpload.FileSystemRepository
import com.nextcloud.client.jobs.autoUpload.SyncFolderHelper
import com.nextcloud.client.jobs.utils.UploadErrorNotificationManager
import com.nextcloud.client.network.ConnectivityService
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.utils.ForegroundServiceHelper
import com.nextcloud.utils.extensions.getPercent
import com.nextcloud.utils.extensions.toFile
import com.nextcloud.utils.extensions.updateStatus
import com.owncloud.android.R
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.ForegroundServiceType
import com.owncloud.android.datamodel.SyncedFolder
import com.owncloud.android.datamodel.SyncedFolderProvider
import com.owncloud.android.datamodel.ThumbnailsCacheManager
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.db.OCUpload
Expand Down Expand Up @@ -57,6 +62,8 @@ class FileUploadWorker(
val localBroadcastManager: LocalBroadcastManager,
private val backgroundJobManager: BackgroundJobManager,
val preferences: AppPreferences,
val filesystemRepository: FileSystemRepository,
val syncedFolderProvider: SyncedFolderProvider,
val context: Context,
params: WorkerParameters
) : CoroutineWorker(context, params),
Expand Down Expand Up @@ -219,10 +226,21 @@ class FileUploadWorker(
val uploads = uploadsStorageManager.getUploadsByIds(uploadIds, accountName)
val ocAccount = OwnCloudAccount(user.toPlatformAccount(), context)
val client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context)
val syncFolderHelper = SyncFolderHelper(context)
val syncedFolders = syncedFolderProvider.syncedFolders

for ((index, upload) in uploads.withIndex()) {
ensureActive()

if (isBelongToAnySyncedFolder(upload, syncFolderHelper, syncedFolders)) {
Log_OC.d(TAG, "skipping upload, will be handled by AutoUploadWorker: ${upload.localPath}")
uploadsStorageManager.uploadDao.deleteByRemotePathAndAccountName(
remotePath = upload.remotePath,
accountName = accountName
)
continue
}

if (preferences.isGlobalUploadPaused) {
Log_OC.d(TAG, "Upload is paused, skip uploading files!")
notificationManager.notifyPaused(
Expand Down Expand Up @@ -266,6 +284,20 @@ class FileUploadWorker(
return@withContext Result.success()
}

suspend fun isBelongToAnySyncedFolder(
upload: OCUpload,
syncFolderHelper: SyncFolderHelper,
syncedFolders: List<SyncedFolder>
): Boolean {
if (!filesystemRepository.isBelongToAnyAutoFolder(upload.localPath)) return false

return syncedFolders.any { folder ->
val file = upload.localPath.toFile() ?: return false
val expectedRemotePath = syncFolderHelper.getAutoUploadRemotePath(folder, file)
expectedRemotePath == upload.remotePath
}
}

private fun sendUploadFinishEvent(
totalUploadSize: Int,
currentUploadIndex: Int,
Expand Down
Loading