Skip to content
Open
Show file tree
Hide file tree
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 @@ -131,20 +131,18 @@ private static boolean isFolder(RemoteFile file) {
}

public static void deleteAllFilesOnServer() {
var result = new ReadFolderRemoteOperation("/").execute(client);
var result = new ReadFolderRemoteOperation("/").execute(nextcloudClient);
assertTrue(result.getLogMessage(targetContext), result.isSuccess());

for (Object object : result.getData()) {
RemoteFile remoteFile = (RemoteFile) object;

for (RemoteFile remoteFile : result.getResultData()) {
if (!Objects.equals(remoteFile.getRemotePath(), "/")) {
if (remoteFile.isEncrypted()) {
ToggleEncryptionRemoteOperation operation = new ToggleEncryptionRemoteOperation(remoteFile.getLocalId(),
remoteFile.getRemotePath(),
false);

boolean operationResult = operation
.execute(client)
.execute(nextcloudClient)
.isSuccess();

if (!operationResult && isFolder(remoteFile)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,15 @@ class OfflineOperationsWorker(
private fun getRemoteFile(remotePath: String): RemoteFile? {
val mimeType = MimeTypeUtil.getMimeTypeFromPath(remotePath)
val isFolder = MimeTypeUtil.isFolder(mimeType)
val client = ClientFactoryImpl(context).create(user)
val result = if (isFolder) {
ReadFolderRemoteOperation(remotePath).execute(client)
} else {
ReadFileRemoteOperation(remotePath).execute(client)
}

return if (result.isSuccess) {
result.data[0] as? RemoteFile
return if (isFolder) {
val nextcloudClient = ClientFactoryImpl(context).createNextcloudClient(user)
val result = ReadFolderRemoteOperation(remotePath).execute(nextcloudClient)
if (result.isSuccess) result.resultData.getOrNull(0) else null
} else {
null
val client = ClientFactoryImpl(context).create(user)
val result = ReadFileRemoteOperation(remotePath).execute(client)
if (result.isSuccess) result.data[0] as? RemoteFile else null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.util.Pair;

import com.nextcloud.client.account.User;
import com.nextcloud.common.NextcloudClient;
import com.nextcloud.utils.e2ee.E2ECounterHelper;
import com.nextcloud.utils.e2ee.E2EVersionHelper;
import com.nextcloud.utils.extensions.OCFileExtensionsKt;
Expand All @@ -30,6 +31,8 @@
import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFile;
import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFolderMetadataFile;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
Expand Down Expand Up @@ -208,8 +211,9 @@ private RemoteOperationResult encryptedCreateV1(OCFile parent, OwnCloudClient cl
}
}

NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, context);
final var remoteFolderOperationResult = new ReadFolderRemoteOperation(encryptedRemotePath)
.execute(client);
.execute(nextcloudClient);

if (remoteFolderOperationResult.isSuccess() && remoteFolderOperationResult.getData().get(0) instanceof RemoteFile remoteFile) {
createdRemoteFolder = remoteFile;
Expand All @@ -220,7 +224,7 @@ private RemoteOperationResult encryptedCreateV1(OCFile parent, OwnCloudClient cl
newDir.getLocalId(),
newDir.getRemotePath(),
true)
.execute(client);
.execute(nextcloudClient);

if (!encryptionOperationResult.isSuccess()) {
throw new RuntimeException("Error creating encrypted subfolder!");
Expand Down Expand Up @@ -360,8 +364,9 @@ private RemoteOperationResult encryptedCreateV2(OCFile parent, OwnCloudClient cl
throw new RuntimeException("Could not unlock folder!");
}

NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, context);
final var remoteFolderOperationResult = new ReadFolderRemoteOperation(encryptedRemotePath)
.execute(client);
.execute(nextcloudClient);

if (remoteFolderOperationResult.isSuccess() && remoteFolderOperationResult.getData().get(0) instanceof RemoteFile remoteFile) {
createdRemoteFolder = remoteFile;
Expand All @@ -372,7 +377,7 @@ private RemoteOperationResult encryptedCreateV2(OCFile parent, OwnCloudClient cl
newDir.getLocalId(),
newDir.getRemotePath(),
true)
.execute(client);
.execute(nextcloudClient);

if (!encryptionOperationResult.isSuccess()) {
throw new RuntimeException("Error creating encrypted subfolder!");
Expand Down Expand Up @@ -517,12 +522,17 @@ private RemoteOperationResult<?> normalCreate(OwnCloudClient client) {
final var result = new CreateFolderRemoteOperation(remotePath, true).execute(client);

if (result.isSuccess()) {
final var remoteFolderOperationResult = new ReadFolderRemoteOperation(remotePath)
.execute(client);
try {
NextcloudClient nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, context);
final var remoteFolderOperationResult = new ReadFolderRemoteOperation(remotePath)
.execute(nextcloudClient);

if (remoteFolderOperationResult.isSuccess() &&
remoteFolderOperationResult.getData().get(0) instanceof RemoteFile remoteFile) {
createdRemoteFolder = remoteFile;
if (remoteFolderOperationResult.isSuccess() &&
remoteFolderOperationResult.getData().get(0) instanceof RemoteFile remoteFile) {
createdRemoteFolder = remoteFile;
}
} catch (AccountUtils.AccountNotFoundException | NullPointerException e) {
Log_OC.e(TAG, "Could not create NextcloudClient to read created folder " + remotePath, e);
}

saveFolderInDB();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {

if (result.isSuccess()) {
if (mRemoteFolderChanged) {
result = fetchAndSyncRemoteFolder(client);
result = fetchAndSyncRemoteFolder();
} else {
Log_OC.d(TAG, "💾 Remote folder is not changed, getting folder content from database");
mChildren = fileDataStorageManager.getFolderContent(mLocalFolder, false);
Expand Down Expand Up @@ -461,9 +461,18 @@ private RemoteOperationResult checkForChanges(OwnCloudClient client) {
return result;
}

private RemoteOperationResult fetchAndSyncRemoteFolder(OwnCloudClient client) {
private RemoteOperationResult fetchAndSyncRemoteFolder() {
String remotePath = mLocalFolder.getRemotePath();
RemoteOperationResult result = new ReadFolderRemoteOperation(remotePath).execute(client);

NextcloudClient nextcloudClient;
try {
nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, mContext);
} catch (AccountUtils.AccountNotFoundException | NullPointerException e) {
Log_OC.e(TAG, "Could not create NextcloudClient to fetch " + remotePath, e);
return new RemoteOperationResult<>(e);
}

RemoteOperationResult result = new ReadFolderRemoteOperation(remotePath).execute(nextcloudClient);
Log_OC.d(TAG, "⬇ eTag is changed or ignored, fetching folder: " + user.getAccountName() + remotePath);

if (result.isSuccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
import com.nextcloud.client.account.User;
import com.nextcloud.client.jobs.download.FileDownloadHelper;
import com.nextcloud.client.jobs.folderDownload.FolderDownloadWorkerNotificationManager;
import com.nextcloud.common.NextcloudClient;
import com.nextcloud.utils.extensions.ExtensionsKt;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.e2e.v1.decrypted.DecryptedFolderMetadataFileV1;
import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFolderMetadataFile;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.operations.OperationCancelledException;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
Expand Down Expand Up @@ -146,13 +149,13 @@ protected RemoteOperationResult run(OwnCloudClient client) {

if (result.isSuccess()) {
if (mRemoteFolderChanged || syncAll) {
result = fetchAndSyncRemoteFolder(client);
result = fetchAndSyncRemoteFolder();
} else {
prepareOpsFromLocalKnowledge();
}

if (result.isSuccess()) {
syncContents(client);
syncContents();
}
}

Expand Down Expand Up @@ -208,13 +211,21 @@ private RemoteOperationResult checkForChanges(OwnCloudClient client) throws Oper
}


private RemoteOperationResult fetchAndSyncRemoteFolder(OwnCloudClient client) throws OperationCancelledException {
private RemoteOperationResult fetchAndSyncRemoteFolder() throws OperationCancelledException {
if (mCancellationRequested.get()) {
throw new OperationCancelledException();
}

NextcloudClient nextcloudClient;
try {
nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, mContext);
} catch (AccountUtils.AccountNotFoundException | NullPointerException e) {
Log_OC.e(TAG, "Could not create NextcloudClient to synchronize " + mRemotePath, e);
return new RemoteOperationResult<>(e);
}

ReadFolderRemoteOperation operation = new ReadFolderRemoteOperation(mRemotePath);
var result = operation.execute(client);
var result = operation.execute(nextcloudClient);
Log_OC.d(TAG, "Synchronizing " + user.getAccountName() + mRemotePath);
Log_OC.d(TAG, "Synchronizing remote id" + mLocalFolder.getRemoteId());

Expand Down Expand Up @@ -442,21 +453,27 @@ private void prepareOpsFromLocalKnowledge() throws OperationCancelledException {
}
}

private void syncContents(OwnCloudClient client) throws OperationCancelledException {
private void syncContents() throws OperationCancelledException {
startDirectDownloads();
startContentSynchronizations(mFilesToSyncContents);
updateETag(client);
updateETag();
}

/**
* Updates the eTag of the local folder after a successful synchronization.
* This ensures that any changes to local files, which may alter the eTag, are correctly reflected.
*
* @param client the OwnCloudClient instance used to execute remote operations.
*/
private void updateETag(OwnCloudClient client) {
private void updateETag() {
NextcloudClient nextcloudClient;
try {
nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, mContext);
} catch (AccountUtils.AccountNotFoundException | NullPointerException e) {
Log_OC.e(TAG, "Could not create NextcloudClient to update eTag of " + mRemotePath, e);
return;
}

ReadFolderRemoteOperation operation = new ReadFolderRemoteOperation(mRemotePath);
final var result = operation.execute(client);
final var result = operation.execute(nextcloudClient);
if (!result.isSuccess()) {
Log_OC.w(TAG, "Cannot update eTag, read folder operation is failed");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ class FolderEncryption(private val fragment: OCFileListFragment) {
val publicKey = provider.getValue(user, EncryptionUtils.PUBLIC_KEY)
val privateKey = provider.getValue(user, EncryptionUtils.PRIVATE_KEY)
val client = fragment.clientFactory.create(user)
val nextcloudClient = fragment.clientFactory.createNextcloudClient(user)

val result = ToggleEncryptionRemoteOperation(localId, remotePath, shouldBeEncrypted)
.execute(client)
.execute(nextcloudClient)

return@withContext when {
result.isSuccess -> onToggleSuccess(
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ org.gradle.configuration-cache=true
org.gradle.workers.max=4

# Needed for local libs
# org.gradle.dependency.verification=off
# systemProp.org.gradle.internal.publish.checksums.insecure=true
org.gradle.dependency.verification=off
systemProp.org.gradle.internal.publish.checksums.insecure=true

# Enabled parallel sync for Gradle 9.4+
org.gradle.tooling.parallel=true
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ androidGifDrawableVersion = "1.2.32"
androidImageCropperVersion = "4.7.0"
androidLibraryVersion ="94372d7cbb8efe1c779ab8c2244a61510efafb28"
androidOpensslVersion = "3.5.6"
androidPluginVersion = "9.3.2"
androidPluginVersion = "9.4.0"
androidsvgVersion = "1.4"
androidxTestVersion = "1.7.0"
annotationVersion = "1.10.0"
Expand Down
5 changes: 3 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ dependencyResolutionManagement {

/*
Needed for local android library

*/

includeBuild("../android_library") {
dependencySubstitution {
substitute(module("com.github.nextcloud:android-library"))
.using(project(":library"))
}
}
*/


/*
Needed for local android common library
Expand Down
Loading