Skip to content

Commit 5ad7286

Browse files
Working new auto folder creation feature on uploads
Signed-off-by: daniele-verducci <daniele.verducci@nextcloud.com>
1 parent 4b14e75 commit 5ad7286

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -473,40 +473,42 @@ protected RemoteOperationResult run(OwnCloudClient client) {
473473
Log_OC.d(TAG, "parent lookup for path: " + remoteParentPath + " → " +
474474
(parent == null ? "not found in DB" : "found, id=" + parent.getFileId()));
475475

476-
final boolean isResumingEncryptedUpload = (mFolderUnlockToken != null && !mFolderUnlockToken.isEmpty());
477-
if (!isResumingEncryptedUpload && (parent == null || mRemoteFolderToBeCreated)) {
478-
Log_OC.d(TAG, "verifying remote parent folder exists: " + remoteParentPath);
479476

480-
if (!getCapabilities().getVersion().isNewerOrEqual(NextcloudVersion.nextcloud_32)) {
481-
// No automatic folder creation before Nextcloud 32, create them
477+
// No automatic folder creation before Nextcloud 32
478+
if (!getCapabilities().getVersion().isNewerOrEqual(NextcloudVersion.nextcloud_32)) {
479+
final boolean isResumingEncryptedUpload = (mFolderUnlockToken != null && !mFolderUnlockToken.isEmpty());
480+
if (!isResumingEncryptedUpload && (parent == null || mRemoteFolderToBeCreated)) {
481+
Log_OC.d(TAG, "verifying remote parent folder exists: " + remoteParentPath);
482482
final var result = grantFolderExistence(remoteParentPath, client);
483+
483484
if (!result.isSuccess()) {
484485
Log_OC.e(TAG, "grantFolderExistence failed for: " + remoteParentPath + ", code: " +
485486
result.getCode() + ", message: " + result.getMessage());
486487
return result;
487488
}
489+
490+
parent = getStorageManager().getFileByPath(remoteParentPath);
491+
if (parent == null) {
492+
Log_OC.e(TAG, "parent still null after grantFolderExistence: " + remoteParentPath);
493+
return new RemoteOperationResult<>(ResultCode.UNKNOWN_ERROR);
494+
}
495+
496+
Log_OC.d(TAG, "remote parent folder confirmed: " + remoteParentPath + ", id=" + parent.getFileId());
488497
}
489498

490-
parent = getStorageManager().getFileByPath(remoteParentPath);
491499
if (parent == null) {
492-
Log_OC.e(TAG, "parent still null after grantFolderExistence: " + remoteParentPath);
493-
return new RemoteOperationResult<>(ResultCode.UNKNOWN_ERROR);
500+
Log_OC.e(TAG, "parent is null, cannot proceed: " + remoteParentPath + "," + " unlock token: " + mFolderUnlockToken);
501+
return new RemoteOperationResult<>(false, "Parent folder not found", HttpStatus.SC_NOT_FOUND);
494502
}
495-
496-
Log_OC.d(TAG, "remote parent folder confirmed: " + remoteParentPath + ", id=" + parent.getFileId());
497503
}
498504

499-
if (parent == null) {
500-
Log_OC.e(TAG, "parent is null, cannot proceed: " + remoteParentPath + "," + " unlock token: " + mFolderUnlockToken);
501-
return new RemoteOperationResult<>(false, "Parent folder not found", HttpStatus.SC_NOT_FOUND);
502-
}
503-
504-
// - resume of encrypted upload, then parent file exists already as unlock is only for direct parent
505-
mFile.setParentId(parent.getFileId());
506-
507505
// check if any parent is encrypted
508506
encryptedAncestor = FileStorageUtils.checkEncryptionStatus(parent, getStorageManager());
509507
mFile.setEncrypted(encryptedAncestor);
508+
if (encryptedAncestor && parent != null) {
509+
// - resume of encrypted upload, then parent file exists already as unlock is only for direct parent
510+
mFile.setParentId(parent.getFileId());
511+
}
510512

511513
if (encryptedAncestor) {
512514
Log_OC.d(TAG, "⬆️🔗" + "encrypted upload");

0 commit comments

Comments
 (0)