Skip to content

Commit 9ef2b06

Browse files
alperozturk96backportbot[bot]
authored andcommitted
handle oc upload construct
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent e945cf3 commit 9ef2b06

4 files changed

Lines changed: 23 additions & 10 deletions

File tree

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+
null
70+
} ?: return null
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: 13 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,18 @@ 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+
var upload = try {
409+
(uploadEntity?.toOCUpload(null) ?: OCUpload(localPath, remotePath, user.accountName))
410+
} catch (_: IllegalArgumentException) {
411+
null
412+
}
413+
414+
if (upload == null) {
415+
Log_OC.e(TAG, "cannot construct oc upload")
416+
return null
417+
}
418+
419+
upload = upload.apply {
414420
uploadStatus = UploadsStorageManager.UploadStatus.UPLOAD_IN_PROGRESS
415421
nameCollisionPolicy = syncedFolder.nameCollisionPolicy
416422
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)