Skip to content

Commit 2a9df81

Browse files
alperozturk96backportbot[bot]
authored andcommitted
fix(upload-list): npe conflict check
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent f4794f8 commit 2a9df81

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,12 @@ public void keepOfflineOperationAndServerFile(OfflineOperationEntity entity, OCF
358358
offlineOperationsRepository.updateNextOperations(entity);
359359
}
360360

361-
private @Nullable
362-
OCFile getFileByPath(String type, String path) {
361+
@Nullable
362+
private OCFile getFileByPath(String type, String path) {
363+
if (path == null) {
364+
return null;
365+
}
366+
363367
final boolean shouldUseEncryptedPath = ProviderTableMeta.FILE_PATH.equals(type);
364368
FileEntity fileEntity = shouldUseEncryptedPath ?
365369
fileDao.getFileByEncryptedRemotePath(path, user.getAccountName()) :

app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -320,21 +320,21 @@ class UploadListActivity :
320320
val client = clientRepository.getOwncloudClient()
321321

322322
// Check parent folder exists
323-
val parentPath = storageManager
324-
.getFileByPath(upload.remotePath)
325-
.parentRemotePath
326-
?: upload.remotePath.webDavParentPath()
327-
328-
val checkOp = ExistenceCheckRemoteOperation(parentPath, false)
329-
val checkResult = checkOp.execute(client)
330-
331-
if (!checkResult.isSuccess &&
332-
checkResult.code == RemoteOperationResult.ResultCode.FILE_NOT_FOUND
333-
) {
334-
withContext(Dispatchers.Main) {
335-
showConflictSnackbar(R.string.uploader_file_not_found_message)
323+
val file = storageManager.getFileByPath(upload.remotePath)
324+
val parentPath = (file?.parentRemotePath ?: upload.remotePath?.webDavParentPath())
325+
326+
parentPath?.let {
327+
val checkOp = ExistenceCheckRemoteOperation(it, false)
328+
val checkResult = checkOp.execute(client)
329+
330+
if (!checkResult.isSuccess &&
331+
checkResult.code == RemoteOperationResult.ResultCode.FILE_NOT_FOUND
332+
) {
333+
withContext(Dispatchers.Main) {
334+
showConflictSnackbar(R.string.uploader_file_not_found_message)
335+
}
336+
return@launch
336337
}
337-
return@launch
338338
}
339339

340340
val result = uploadFileOperationFactory

0 commit comments

Comments
 (0)