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 @@ -175,7 +175,7 @@ interface BackgroundJobManager {
fun startPeriodicallyOfflineOperation()
fun scheduleInternal2WaySync(intervalMinutes: Long)
fun cancelAllFilesDownloadJobs()
fun startMetadataSyncJob(currentDirPath: String)
fun startMetadataSyncJob(currentDirPath: String, folderAlreadySynced: Boolean = false)
fun downloadFolder(folder: OCFile, accountName: String)
fun cancelFolderDownload()
fun locallyDeleteAutoUploadedFiles(syncedFolders: List<SyncedFolder>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,10 @@ internal class BackgroundJobManagerImpl(
workManager.cancelAllWorkByTag(formatClassTag(FileDownloadWorker::class))
}

override fun startMetadataSyncJob(currentDirPath: String) {
override fun startMetadataSyncJob(currentDirPath: String, folderAlreadySynced: Boolean) {
val inputData = Data.Builder()
.putString(MetadataWorker.FILE_PATH, currentDirPath)
.putBoolean(MetadataWorker.FOLDER_ALREADY_SYNCED, folderAlreadySynced)
.build()

val constrains = Constraints.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class MetadataWorker(private val context: Context, params: WorkerParameters, pri
companion object {
private const val TAG = "MetadataWorker"
const val FILE_PATH = "file_path"
const val FOLDER_ALREADY_SYNCED = "folder_already_synced"
}

override suspend fun doWork(): Result {
Expand All @@ -49,7 +50,8 @@ class MetadataWorker(private val context: Context, params: WorkerParameters, pri

Log_OC.d(TAG, "Starting metadata sync for folder: $filePath, id: ${currentDir.fileId}")

if (!refreshFolder(currentDir, storageManager)) return Result.failure()
val folderAlreadySynced = inputData.getBoolean(FOLDER_ALREADY_SYNCED, false)
if (!folderAlreadySynced && !refreshFolder(currentDir, storageManager)) return Result.failure()

val refreshedDir = storageManager.getFileByPath(filePath) ?: run {
Log_OC.e(TAG, "File not found after refresh: $filePath")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ private void updatePredefinedStatus(ArbitraryDataProvider arbitraryDataProvider)

private RemoteOperationResult checkForChanges(OwnCloudClient client) {
mRemoteFolderChanged = true;

if (mIgnoreETag) {
return new RemoteOperationResult<>(ResultCode.OK);
}

RemoteOperationResult<?> result;
String remotePath = mLocalFolder.getRemotePath();

Expand All @@ -418,25 +423,21 @@ private RemoteOperationResult checkForChanges(OwnCloudClient client) {
if (result.isSuccess()) {
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));

if (!mIgnoreETag) {
// check if remote and local folder are different
String remoteFolderETag = remoteFolder.getEtag();
if (remoteFolderETag != null) {
String localFolderEtag = mLocalFolder.getEtag();
mRemoteFolderChanged = StringExtensionsKt.eTagChanged(remoteFolderETag, localFolderEtag);
Log_OC.d(
TAG,
"📂 eTag check\n" +
" Path: " + remoteFolder.getRemotePath() + "\n" +
" Local eTag: " + localFolderEtag + "\n" +
" Remote eTag: " + remoteFolderETag + "\n" +
" Changed: " + mRemoteFolderChanged
);
} else {
Log_OC.e(TAG, "Checked " + user.getAccountName() + remotePath + ": No ETag received from server");
}
// check if remote and local folder are different
String remoteFolderETag = remoteFolder.getEtag();
if (remoteFolderETag != null) {
String localFolderEtag = mLocalFolder.getEtag();
mRemoteFolderChanged = StringExtensionsKt.eTagChanged(remoteFolderETag, localFolderEtag);
Log_OC.d(
TAG,
"📂 eTag check\n" +
" Path: " + remoteFolder.getRemotePath() + "\n" +
" Local eTag: " + localFolderEtag + "\n" +
" Remote eTag: " + remoteFolderETag + "\n" +
" Changed: " + mRemoteFolderChanged
);
} else {
Log_OC.d(TAG, "Ignoring eTag. mRemoteFolderChanged is true.");
Log_OC.e(TAG, "Checked " + user.getAccountName() + remotePath + ": No ETag received from server");
}

result = new RemoteOperationResult<>(ResultCode.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ class FileDisplayActivity :

checkStoragePath()
observeWorkerState()
startMetadataSyncForRoot()
handleBackPress()
setupDrawer(menuItemId)
}
Expand Down Expand Up @@ -1612,6 +1611,10 @@ class FileDisplayActivity :
file = currentFile
}

if (isSyncFolderRemotePathRoot) {
startMetadataSyncForRoot()
}

handleSyncResult(event, syncResult)
DataHolderUtil.getInstance().delete(id)
handleScrollBehaviour(fileListFragment)
Expand Down Expand Up @@ -3289,7 +3292,7 @@ class FileDisplayActivity :

// region MetadataSyncJob
private fun startMetadataSyncForRoot() {
backgroundJobManager.startMetadataSyncJob(OCFile.ROOT_PATH)
backgroundJobManager.startMetadataSyncJob(OCFile.ROOT_PATH, folderAlreadySynced = true)
}

private fun startMetadataSyncForCurrentDir() {
Expand Down
Loading