Skip to content

Commit c2e4c71

Browse files
Merge pull request #16181 from nextcloud/backport/16142/stable-3.35
[stable-3.35] fix: search task root sub dir content fetch
2 parents 1bc71f8 + e3dfa42 commit c2e4c71

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import com.owncloud.android.MainApp;
5252
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
5353
import com.owncloud.android.lib.common.network.WebdavEntry;
54-
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
5554
import com.owncloud.android.lib.common.utils.Log_OC;
5655
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
5756
import com.owncloud.android.lib.resources.files.model.FileLockType;
@@ -497,9 +496,13 @@ public List<OCFile> getFolderImages(OCFile folder, boolean onlyOnDevice) {
497496
}
498497

499498
public boolean saveFile(OCFile ocFile) {
499+
Log_OC.d(TAG, "saving file: " + ocFile.getRemotePath());
500+
500501
boolean overridden = false;
501502
final ContentValues cv = createContentValuesForFile(ocFile);
502503
if (ocFile.isFolder()) {
504+
// only refresh folder operation must update eTag otherwise content of the folder may stay as outdated
505+
cv.remove(ProviderTableMeta.FILE_ETAG);
503506
cv.remove(ProviderTableMeta.FILE_STORAGE_PATH);
504507
}
505508

@@ -547,46 +550,65 @@ public boolean saveFile(OCFile ocFile) {
547550
}
548551

549552
/**
550-
* traverses a files parent tree to be able to store a file with its parents. Throws a
551-
* RemoteOperationFailedException in case the parent can't be retrieved.
553+
* Ensures that an {@link OCFile} and all of its parent folders are stored locally.
554+
* <p>
555+
* If the file has no parent ID and is not the root folder, this method recursively:
556+
* <ul>
557+
* <li>Resolves the parent path</li>
558+
* <li>Loads the parent from local storage or fetches it from the server</li>
559+
* <li>Saves all missing parent folders</li>
560+
* <li>Assigns the resolved parent ID to the file</li>
561+
* </ul>
562+
*
563+
* @param ocFile the file to be saved together with its parent hierarchy
564+
* @param context Android context used for remote operations
565+
*
566+
* @return the same {@link OCFile} instance with a valid parent ID
552567
*
553-
* @param ocFile the file
554-
* @param context the app context
555-
* @return the parent file
568+
* @throws RemoteOperationFailedException if a parent folder cannot be retrieved
569+
* from the server
556570
*/
557571
public OCFile saveFileWithParent(OCFile ocFile, Context context) {
558572
if (ocFile.getParentId() == 0 && !OCFile.ROOT_PATH.equals(ocFile.getRemotePath())) {
573+
Log_OC.d(TAG, "saving file with parents: " + ocFile.getRemotePath());
574+
559575
String remotePath = ocFile.getRemotePath();
560576
String parentPath = remotePath.substring(0, remotePath.lastIndexOf(ocFile.getFileName()));
561577

562578
OCFile parentFile = getFileByPath(parentPath);
563579
OCFile returnFile;
564580

565581
if (parentFile == null) {
566-
// remote request
567-
ReadFileRemoteOperation operation = new ReadFileRemoteOperation(parentPath);
568-
// TODO Deprecated
569-
RemoteOperationResult result = operation.execute(getUser(), context);
570-
if (result.isSuccess()) {
571-
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
572-
573-
returnFile = saveFileWithParent(remoteFolder, context);
582+
Log_OC.d(TAG, "Parent not found locally, fetching: " + parentPath);
583+
584+
final var operation = new ReadFileRemoteOperation(parentPath);
585+
final var result = operation.execute(getUser(), context);
586+
587+
if (result.isSuccess() && result.getData().get(0) instanceof RemoteFile remoteFile) {
588+
OCFile folder = FileStorageUtils.fillOCFile(remoteFile);
589+
Log_OC.d(TAG, "Fetched parent folder: " + folder);
590+
returnFile = saveFileWithParent(folder, context);
574591
} else {
575592
Exception exception = result.getException();
576593
String message = "Error during saving file with parents: " + ocFile.getRemotePath() + " / "
577594
+ result.getLogMessage(context);
578595

596+
Log_OC.e(TAG, message);
597+
579598
if (exception != null) {
580599
throw new RemoteOperationFailedException(message, exception);
581600
} else {
582601
throw new RemoteOperationFailedException(message);
583602
}
584603
}
585604
} else {
605+
Log_OC.d(TAG, "parent file exists, calling saveFileWithParent: " + ocFile.getRemotePath());
586606
returnFile = saveFileWithParent(parentFile, context);
587607
}
588608

589-
ocFile.setParentId(returnFile.getFileId());
609+
long parentId = returnFile.getFileId();
610+
Log_OC.d(TAG, "saving parent id of: " + ocFile.getRemotePath() + " with: " + parentId);
611+
ocFile.setParentId(parentId);
590612
saveFile(ocFile);
591613
}
592614

app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,6 @@ private void updatePredefinedStatus(ArbitraryDataProvider arbitraryDataProvider)
400400

401401
private RemoteOperationResult checkForChanges(OwnCloudClient client) {
402402
mRemoteFolderChanged = true;
403-
if (isMetadataSyncWorkerRunning) {
404-
Log_OC.d(TAG, "Skipping eTag check since metadata worker already did");
405-
return new RemoteOperationResult<>(ResultCode.OK);
406-
}
407-
408403
RemoteOperationResult<?> result;
409404
String remotePath = mLocalFolder.getRemotePath();
410405

@@ -414,16 +409,18 @@ private RemoteOperationResult checkForChanges(OwnCloudClient client) {
414409
result = new ReadFileRemoteOperation(remotePath).execute(client);
415410

416411
if (result.isSuccess()) {
417-
if (!mIgnoreETag && result.getData().get(0) instanceof RemoteFile remoteFile) {
412+
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
413+
414+
if (!mIgnoreETag) {
418415
// check if remote and local folder are different
419-
String remoteFolderETag = remoteFile.getEtag();
416+
String remoteFolderETag = remoteFolder.getEtag();
420417
if (remoteFolderETag != null) {
421418
String localFolderEtag = mLocalFolder.getEtag();
422419
mRemoteFolderChanged = StringExtensionsKt.eTagChanged(remoteFolderETag, localFolderEtag);
423420
Log_OC.d(
424421
TAG,
425422
"📂 eTag check\n" +
426-
" Path: " + remoteFile.getRemotePath() + "\n" +
423+
" Path: " + remoteFolder.getRemotePath() + "\n" +
427424
" Local eTag: " + localFolderEtag + "\n" +
428425
" Remote eTag: " + remoteFolderETag + "\n" +
429426
" Changed: " + mRemoteFolderChanged
@@ -502,7 +499,7 @@ private void synchronizeData(List<Object> folderAndFiles) {
502499
mLocalFolder = fileDataStorageManager.getFileByPath(mLocalFolder.getRemotePath());
503500

504501
if (mLocalFolder == null) {
505-
Log_OC.d(TAG,"mLocalFolder cannot be null");
502+
Log_OC.e(TAG,"mLocalFolder cannot be null");
506503
return;
507504
}
508505

@@ -511,7 +508,7 @@ private void synchronizeData(List<Object> folderAndFiles) {
511508
remoteFolder.setParentId(mLocalFolder.getParentId());
512509
remoteFolder.setFileId(mLocalFolder.getFileId());
513510

514-
Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data ");
511+
Log_OC.d(TAG, "Remote folder path: " + mLocalFolder.getRemotePath() + " changed - starting update of local data ");
515512

516513
List<OCFile> updatedFiles = new ArrayList<>(folderAndFiles.size() - 1);
517514
mFilesToSyncContents.clear();

0 commit comments

Comments
 (0)