Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -524,30 +524,32 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
return result;
}

long counter = getE2ECounter(parentFile);

try {
token = getFolderUnlockTokenOrLockFolder(client, parentFile, counter);
} catch (Exception e) {
Log_OC.e(TAG, "Failed to lock folder", e);
return new RemoteOperationResult<>(e);
}

// Update metadata
EncryptionUtilsV2 encryptionUtilsV2 = new EncryptionUtilsV2();
object = EncryptionUtils.downloadFolderMetadata(parentFile, client, mContext, user);
if (object instanceof DecryptedFolderMetadataFileV1 decrypted && decrypted.getMetadata() != null) {
metadataExists = true;
}

if (isEndToEndVersionAtLeastV2()) {
boolean isEndToEndVersionAtLeastV2 = isEndToEndVersionAtLeastV2();

if (isEndToEndVersionAtLeastV2) {
if (object == null) {
return new RemoteOperationResult<>(new IllegalStateException("Metadata does not exist"));
}
} else {
object = getDecryptedFolderMetadataV1(publicKey, object);
}

long counter = getE2ECounter(parentFile, object, isEndToEndVersionAtLeastV2);
Log_OC.d(TAG, "counter: " + counter);

try {
token = getFolderUnlockTokenOrLockFolder(client, parentFile, counter);
} catch (Exception e) {
Log_OC.e(TAG, "Failed to lock folder", e);
return new RemoteOperationResult<>(e);
}

E2EClientData clientData = new E2EClientData(client, token, publicKey);

List<String> fileNames = getCollidedFileNames(object);
Expand Down Expand Up @@ -621,14 +623,16 @@ private boolean isEndToEndVersionAtLeastV2() {
return E2EVersionHelper.INSTANCE.isV2Plus(capability);
}

private long getE2ECounter(OCFile parentFile) {
long counter = -1;
private long getE2ECounter(OCFile parentFile, Object metadata, boolean isEndToEndVersionAtLeastV2) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already fetching metadata it was not used for counter.

if (!isEndToEndVersionAtLeastV2) {
return -1;
}

if (isEndToEndVersionAtLeastV2()) {
counter = parentFile.getE2eCounter() + 1;
if (metadata instanceof DecryptedFolderMetadataFile decrypted) {
return decrypted.getMetadata().getCounter() + 1;
}

return counter;
return parentFile.getE2eCounter() + 1;
}

private String getFolderUnlockTokenOrLockFolder(OwnCloudClient client, OCFile parentFile, long counter) throws UploadException {
Expand Down Expand Up @@ -900,6 +904,9 @@ private void updateMetadataForV2(DecryptedFolderMetadataFile metadata, Encryptio
metadata,
getStorageManager());

parentFile.setE2eCounter(metadata.getMetadata().getCounter());
getStorageManager().saveFile(parentFile);

// upload metadata
encryptionUtilsV2.serializeAndUploadMetadata(parentFile,
metadata,
Expand Down
Loading