File tree Expand file tree Collapse file tree 4 files changed +19
-10
lines changed
Expand file tree Collapse file tree 4 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta
1818import com.owncloud.android.db.UploadResult
1919import com.owncloud.android.files.services.NameCollisionPolicy
2020import com.owncloud.android.lib.resources.status.OCCapability
21+ import java.lang.IllegalArgumentException
2122
2223@Entity(tableName = ProviderTableMeta .UPLOADS_TABLE_NAME )
2324data 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() }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments