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 @@ -55,7 +55,7 @@ class MetadataWorker(private val context: Context, params: WorkerParameters, pri
return Result.success()
}

@Suppress("DEPRECATION")
@Suppress("DEPRECATION", "TooGenericExceptionCaught")
private suspend fun refreshFolder(folder: OCFile, storageManager: FileDataStorageManager) =
withContext(Dispatchers.IO) {
Log_OC.d(
Expand All @@ -72,12 +72,23 @@ class MetadataWorker(private val context: Context, params: WorkerParameters, pri

Log_OC.d(TAG, "⏳ Fetching metadata for: ${folder.remotePath}")

val operation = RefreshFolderOperation(folder, storageManager, user, context)
val result = operation.execute(user, context)
if (result.isSuccess) {
Log_OC.d(TAG, "✅ Successfully fetched metadata for: ${folder.remotePath}")
} else {
Log_OC.e(TAG, "❌ Failed to fetch metadata for: ${folder.remotePath}")
try {
val operation = RefreshFolderOperation(folder, storageManager, user, context)
val result = operation.execute(user, context)
if (result.isSuccess) {
Log_OC.d(TAG, "✅ Successfully fetched metadata for: ${folder.remotePath}")
} else {
Log_OC.e(TAG, "❌ Failed to fetch metadata for: ${folder.remotePath}, resetting e-Tag")
resetETag(folder, storageManager)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can safely reset the e-Tag if the RefreshFolderOperation fails. Since the operation is only executed when the e-Tag differs, setting it back to null in the event of a failure is acceptable and will not trigger any unnecessary additional operations.

}
} catch (e: Exception) {
Log_OC.e(TAG, "❌ Exception during to fetch metadata for: ${folder.remotePath}, resetting e-Tag $e")
resetETag(folder, storageManager)
}
}

private fun resetETag(folder: OCFile, storageManager: FileDataStorageManager) {
folder.etag = ""
storageManager.saveFile(folder)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,6 @@ private void synchronizeData(List<Object> folderAndFiles) {
// update richWorkspace
mLocalFolder.setRichWorkspace(remoteFolder.getRichWorkspace());

// update eTag
mLocalFolder.setEtag(remoteFolder.getEtag());

// update size
mLocalFolder.setFileLength(remoteFolder.getFileLength());

Object object = null;
if (mLocalFolder.isEncrypted()) {
object = getDecryptedFolderMetadata(encryptedAncestor,
Expand Down Expand Up @@ -619,6 +613,7 @@ private void synchronizeData(List<Object> folderAndFiles) {
updatedFile.setEncrypted(encrypted);

updatedFiles.add(updatedFile);
Log_OC.d(TAG, "folder: " + mLocalFolder.getRemotePath() + " file: " + updatedFile.getRemotePath() + " metadataWorking: " + isMetadataSyncWorkerRunning);
}


Expand All @@ -634,8 +629,13 @@ private void synchronizeData(List<Object> folderAndFiles) {
mLocalFolder);
}
fileDataStorageManager.saveFolder(remoteFolder, updatedFiles, localFilesMap.values());

mChildren = updatedFiles;

// update eTag
mLocalFolder.setEtag(remoteFolder.getEtag());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only update mLocalFolder e-Tag and file-length after saving all children files to the directory.

Later on in run fileDataStorageManager.saveFile(mLocalFolder); will be called after fetchAndSyncRemoteFolder


// update size
mLocalFolder.setFileLength(remoteFolder.getFileLength());
}

@Nullable
Expand Down
Loading