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 @@ -37,6 +37,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -126,6 +127,10 @@ protected RemoteOperationResult run(OwnCloudClient client) {
try {
// get locally cached information about folder
mLocalFolder = getStorageManager().getFileByPath(mRemotePath);
if (mLocalFolder == null) {
Log_OC.e(TAG, "Local folder is null, cannot run synchronize folder operation, remote path: " + mRemotePath);
return new RemoteOperationResult<>(ResultCode.FILE_NOT_FOUND);
}

result = checkForChanges(client);

Expand Down Expand Up @@ -163,18 +168,17 @@ private RemoteOperationResult checkForChanges(OwnCloudClient client) throws Oper

// remote request
ReadFileRemoteOperation operation = new ReadFileRemoteOperation(mRemotePath);
RemoteOperationResult result = operation.execute(client);
if (result.isSuccess()) {
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
var result = operation.execute(client);
if (result.isSuccess() && result.getData().get(0) instanceof RemoteFile remoteFile) {
OCFile remoteFolder = FileStorageUtils.fillOCFile(remoteFile);

// check if remote and local folder are different
mRemoteFolderChanged = !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag()));

result = new RemoteOperationResult(ResultCode.OK);
result = new RemoteOperationResult<>(ResultCode.OK);

Log_OC.i(TAG, "Checked " + user.getAccountName() + mRemotePath + " : " +
(mRemoteFolderChanged ? "changed" : "not changed"));

(mRemoteFolderChanged ? "changed" : "not changed"));
} else {
// check failed
if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
Expand Down Expand Up @@ -549,12 +553,20 @@ public void cancel() {
mCancellationRequested.set(true);
}

public String getFolderPath() {
public Optional<String> getFolderNameFromPath() {
if (mLocalFolder == null) {
return Optional.empty();
}

String path = mLocalFolder.getStoragePath();
if (!TextUtils.isEmpty(path)) {
return path;
File folder = new File(path);
return Optional.of(folder.getName());
}
return FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), mLocalFolder);

String filepath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), mLocalFolder);
File folder = new File(filepath);
return Optional.of(folder.getName());
}

private void startSyncFolderOperation(String path){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import java.io.File;
import java.net.SocketTimeoutException;
import java.util.Optional;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -160,10 +161,13 @@ String getMessageForSynchronizeFolderOperation(
Resources res) {

if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND) {
return String.format(
res.getString(R.string.sync_current_folder_was_removed),
new File(operation.getFolderPath()).getName()
);
Optional<String> folderName = operation.getFolderNameFromPath();
if (folderName.isEmpty()) {
return null;
}

String format = res.getString(R.string.sync_current_folder_was_removed);
return String.format(format, folderName.get());
}
return null;
}
Expand Down Expand Up @@ -488,11 +492,14 @@ String getMessageForOperation(RemoteOperation operation, Resources res) {
} else if (operation instanceof MoveFileOperation) {
message = res.getString(R.string.move_file_error);

} else if (operation instanceof SynchronizeFolderOperation) {
String folderPathName = new File(
((SynchronizeFolderOperation) operation).getFolderPath()
).getName();
message = String.format(res.getString(R.string.sync_folder_failed_content), folderPathName);
} else if (operation instanceof SynchronizeFolderOperation synchronizeFolderOperation) {
Optional<String> folderName = synchronizeFolderOperation.getFolderNameFromPath();
if (folderName.isEmpty()) {
return null;
}

String format = res.getString(R.string.sync_folder_failed_content);
message = String.format(format, folderName.get());

} else if (operation instanceof CopyFileOperation) {
message = res.getString(R.string.copy_file_error);
Expand Down
Loading