@@ -481,7 +481,7 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
481481 E2EFiles e2eFiles = new E2EFiles (parentFile , null , new File (mOriginalStoragePath ), null , null );
482482 FileLock fileLock = null ;
483483 long size ;
484-
484+ boolean folderWasLocked = false ;
485485 boolean metadataExists = false ;
486486 String token = null ;
487487 Object object = null ;
@@ -497,7 +497,20 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
497497 }
498498
499499 long counter = getE2ECounter (parentFile );
500- token = getFolderUnlockTokenOrLockFolder (client , parentFile , counter );
500+
501+ try {
502+ token = getFolderUnlockTokenOrLockFolder (client , parentFile , counter );
503+
504+ if (token == null || token .isEmpty ()) {
505+ Log_OC .e (TAG , "Failed to obtain folder lock token for encrypted upload" );
506+ return new RemoteOperationResult <>(new IllegalStateException ("Cannot proceed: folder lock token is null or empty" ));
507+ }
508+ folderWasLocked = true ;
509+ Log_OC .d (TAG , "folder successfully locked" );
510+ } catch (Exception e ) {
511+ Log_OC .e (TAG , "Failed to lock folder" , e );
512+ return new RemoteOperationResult <>(e );
513+ }
501514
502515 // Update metadata
503516 EncryptionUtilsV2 encryptionUtilsV2 = new EncryptionUtilsV2 ();
@@ -508,7 +521,7 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
508521
509522 if (isEndToEndVersionAtLeastV2 ()) {
510523 if (object == null ) {
511- return new RemoteOperationResult (new IllegalStateException ("Metadata does not exist" ));
524+ return new RemoteOperationResult <> (new IllegalStateException ("Metadata does not exist" ));
512525 }
513526 } else {
514527 object = getDecryptedFolderMetadataV1 (publicKey , object );
@@ -518,7 +531,7 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
518531
519532 List <String > fileNames = getCollidedFileNames (object );
520533
521- RemoteOperationResult collisionResult = checkNameCollision (parentFile , client , fileNames , parentFile .isEncrypted ());
534+ final var collisionResult = checkNameCollision (parentFile , client , fileNames , parentFile .isEncrypted ());
522535 if (collisionResult != null ) {
523536 result = collisionResult ;
524537 return collisionResult ;
@@ -563,13 +576,13 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
563576 }
564577 } catch (FileNotFoundException e ) {
565578 Log_OC .e (TAG , mFile .getStoragePath () + " does not exist anymore" );
566- result = new RemoteOperationResult (ResultCode .LOCAL_FILE_NOT_FOUND );
579+ result = new RemoteOperationResult <> (ResultCode .LOCAL_FILE_NOT_FOUND );
567580 } catch (OverlappingFileLockException e ) {
568581 Log_OC .e (TAG , "Overlapping file lock exception" );
569- result = new RemoteOperationResult (ResultCode .LOCK_FAILED );
582+ result = new RemoteOperationResult <> (ResultCode .LOCK_FAILED );
570583 } catch (Exception e ) {
571584 Log_OC .e (TAG , "UploadFileOperation exception: " + e .getLocalizedMessage ());
572- result = new RemoteOperationResult (e );
585+ result = new RemoteOperationResult <> (e );
573586 } finally {
574587 result = cleanupE2EUpload (fileLock , e2eFiles , result , object , client , token );
575588 }
0 commit comments