Skip to content

Commit cea63ae

Browse files
Merge pull request #16341 from nextcloud/backport/16340/stable-3.35
[stable-3.35] handle oc upload construct
2 parents e945cf3 + cfec946 commit cea63ae

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

app/src/main/java/com/nextcloud/client/database/entity/UploadEntity.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
1818
import com.owncloud.android.db.UploadResult
1919
import com.owncloud.android.files.services.NameCollisionPolicy
2020
import com.owncloud.android.lib.resources.status.OCCapability
21+
import java.lang.IllegalArgumentException
2122

2223
@Entity(tableName = ProviderTableMeta.UPLOADS_TABLE_NAME)
2324
data class UploadEntity(
@@ -56,13 +57,17 @@ data class UploadEntity(
5657
val folderUnlockToken: String?
5758
)
5859

59-
fun UploadEntity.toOCUpload(capability: OCCapability? = null): OCUpload {
60+
fun UploadEntity.toOCUpload(capability: OCCapability? = null): OCUpload? {
6061
val localPath = localPath
6162
var remotePath = remotePath
6263
if (capability != null && remotePath != null) {
6364
remotePath = AutoRename.rename(remotePath, capability)
6465
}
65-
val upload = OCUpload(localPath, remotePath, accountName)
66+
val upload = try {
67+
OCUpload(localPath, remotePath, accountName)
68+
} catch (_: IllegalArgumentException) {
69+
return null
70+
}
6671

6772
fileSize?.let { upload.fileSize = it }
6873
id?.let { upload.uploadId = it.toLong() }

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ class AutoUploadWorker(
383383
uploadsStorageManager.removeUpload(upload)
384384
}
385385

386+
@Suppress("ReturnCount")
386387
private fun createEntityAndUpload(
387388
user: User,
388389
localPath: String,
@@ -404,13 +405,14 @@ class AutoUploadWorker(
404405
return null
405406
}
406407

407-
val upload = (
408-
uploadEntity?.toOCUpload(null) ?: OCUpload(
409-
localPath,
410-
remotePath,
411-
user.accountName
412-
)
413-
).apply {
408+
val upload = try {
409+
uploadEntity?.toOCUpload(null) ?: OCUpload(localPath, remotePath, user.accountName)
410+
} catch (_: IllegalArgumentException) {
411+
Log_OC.e(TAG, "cannot construct oc upload")
412+
return null
413+
}
414+
415+
upload.apply {
414416
uploadStatus = UploadsStorageManager.UploadStatus.UPLOAD_IN_PROGRESS
415417
nameCollisionPolicy = syncedFolder.nameCollisionPolicy
416418
isUseWifiOnly = needsWifi

app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class FileUploadHelper {
299299
dao.getUploadsByAccountNameAndStatus(accountName, status.value, nameCollisionPolicy?.serialize())
300300
} else {
301301
dao.getUploadsByStatus(status.value, nameCollisionPolicy?.serialize())
302-
}.map { it.toOCUpload(null) }.toTypedArray()
302+
}.mapNotNull { it.toOCUpload(null) }.toTypedArray()
303303
onCompleted(result)
304304
}
305305
}

app/src/main/java/com/owncloud/android/db/OCUpload.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ public class OCUpload implements Parcelable {
130130
*/
131131
public OCUpload(String localPath, String remotePath, String accountName) {
132132
if (localPath == null || !localPath.startsWith(File.separator)) {
133+
Log_OC.e(TAG, "oc upload, local path: " + localPath);
133134
throw new IllegalArgumentException("Local path must be an absolute path in the local file system");
134135
}
135136
if (remotePath == null || !remotePath.startsWith(OCFile.PATH_SEPARATOR)) {
137+
Log_OC.e(TAG, "oc upload, remote path: " + remotePath);
136138
throw new IllegalArgumentException("Remote path must be an absolute path in the local file system");
137139
}
138140
if (accountName == null || accountName.length() < 1) {

0 commit comments

Comments
 (0)