|
37 | 37 | import java.util.ArrayList; |
38 | 38 | import java.util.List; |
39 | 39 | import java.util.Map; |
| 40 | +import java.util.Optional; |
40 | 41 | import java.util.Vector; |
41 | 42 | import java.util.concurrent.atomic.AtomicBoolean; |
42 | 43 |
|
@@ -126,6 +127,10 @@ protected RemoteOperationResult run(OwnCloudClient client) { |
126 | 127 | try { |
127 | 128 | // get locally cached information about folder |
128 | 129 | mLocalFolder = getStorageManager().getFileByPath(mRemotePath); |
| 130 | + if (mLocalFolder == null) { |
| 131 | + Log_OC.e(TAG, "Local folder is null, cannot run synchronize folder operation, remote path: " + mRemotePath); |
| 132 | + return new RemoteOperationResult<>(ResultCode.FILE_NOT_FOUND); |
| 133 | + } |
129 | 134 |
|
130 | 135 | result = checkForChanges(client); |
131 | 136 |
|
@@ -163,18 +168,17 @@ private RemoteOperationResult checkForChanges(OwnCloudClient client) throws Oper |
163 | 168 |
|
164 | 169 | // remote request |
165 | 170 | ReadFileRemoteOperation operation = new ReadFileRemoteOperation(mRemotePath); |
166 | | - RemoteOperationResult result = operation.execute(client); |
167 | | - if (result.isSuccess()) { |
168 | | - OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0)); |
| 171 | + var result = operation.execute(client); |
| 172 | + if (result.isSuccess() && result.getData().get(0) instanceof RemoteFile remoteFile) { |
| 173 | + OCFile remoteFolder = FileStorageUtils.fillOCFile(remoteFile); |
169 | 174 |
|
170 | 175 | // check if remote and local folder are different |
171 | 176 | mRemoteFolderChanged = !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag())); |
172 | 177 |
|
173 | | - result = new RemoteOperationResult(ResultCode.OK); |
| 178 | + result = new RemoteOperationResult<>(ResultCode.OK); |
174 | 179 |
|
175 | 180 | Log_OC.i(TAG, "Checked " + user.getAccountName() + mRemotePath + " : " + |
176 | | - (mRemoteFolderChanged ? "changed" : "not changed")); |
177 | | - |
| 181 | + (mRemoteFolderChanged ? "changed" : "not changed")); |
178 | 182 | } else { |
179 | 183 | // check failed |
180 | 184 | if (result.getCode() == ResultCode.FILE_NOT_FOUND) { |
@@ -549,12 +553,20 @@ public void cancel() { |
549 | 553 | mCancellationRequested.set(true); |
550 | 554 | } |
551 | 555 |
|
552 | | - public String getFolderPath() { |
| 556 | + public Optional<String> getFolderNameFromPath() { |
| 557 | + if (mLocalFolder == null) { |
| 558 | + return Optional.empty(); |
| 559 | + } |
| 560 | + |
553 | 561 | String path = mLocalFolder.getStoragePath(); |
554 | 562 | if (!TextUtils.isEmpty(path)) { |
555 | | - return path; |
| 563 | + File folder = new File(path); |
| 564 | + return Optional.of(folder.getName()); |
556 | 565 | } |
557 | | - return FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), mLocalFolder); |
| 566 | + |
| 567 | + String filepath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), mLocalFolder); |
| 568 | + File folder = new File(filepath); |
| 569 | + return Optional.of(folder.getName()); |
558 | 570 | } |
559 | 571 |
|
560 | 572 | private void startSyncFolderOperation(String path){ |
|
0 commit comments