Skip to content

Fix recursive folder sync#16602

Open
l3pr-org wants to merge 5 commits intonextcloud:masterfrom
l3pr-org:fix/recursive-sync
Open

Fix recursive folder sync#16602
l3pr-org wants to merge 5 commits intonextcloud:masterfrom
l3pr-org:fix/recursive-sync

Conversation

@l3pr-org
Copy link

Summary

This PR fixes #269 , the inability to recursively sync folders (an issue that is 10 years old). Previously, when users tried to sync a folder with subfolders recursively, only the immediate children were synced. I spent three days of time I should have been focusing on my programming assignments on this, so please let me know if there is anything wrong with my code instead of just throwing it out. I am happy to collaborate, but I needed this feature so that I can properly sync and listen to my music.

Root Cause

The issue had three contributing factors:

  1. Race Condition: MetadataWorker and FolderDownloadWorker were running without proper dependency, causing FolderDownloadWorker to query the database before metadata was populated.

  2. eTag Caching: MetadataWorker was skipping folder content refresh when eTag hadn't changed, leaving the database empty.

  3. Single-Level Processing: MetadataWorker only fetched one level of subfolders, not recursively traversing into nested folders like Artists/ABBA, for example.

Changes

  • BackgroundJobManagerImpl.kt: Added WorkManager job dependency chain to ensure MetadataWorker runs before FolderDownloadWorker
  • MetadataWorker.kt:
    • Added FORCE_REFRESH flag to bypass eTag caching
    • Implemented BFS-based recursive folder processing to fetch metadata for ALL nested subfolders
  • FolderDownloadWorker.kt: Added debug logging and warning when no files found
  • UI Components: Added "Download all subfolders" option in file actions with confirmation dialog

🏁 Checklist

  • Tests written, or not not needed (existing tests cover core functionality; new functionality requires instrumented tests with a real Nextcloud server)
  • Tested locally on device

Stanley added 5 commits February 27, 2026 04:26
- Make FileDataStorageManager.getFolderContent() public to allow MetadataWorker access
- Add recursive parameter to BackgroundJobManager.downloadFolder() with default false
- Add job dependency in BackgroundJobManagerImpl to ensure MetadataWorker runs before FolderDownloadWorker
- Add recursive parameter to FileDownloadHelper.downloadFolder()
- Pass recursive parameter in SynchronizeFolderOperation
- Add FORCE_REFRESH flag to bypass eTag caching and always fetch fresh content
- Implement BFS-based recursive folder processing to fetch metadata for ALL nested subfolders
- Before: Only processed one level of subfolders (e.g., Artists but not ABBA inside it)
- After: Recursively processes all nested folders at every depth level
- Also fetches files at each folder level to ensure FolderDownloadWorker has access to all files
- Add warning log when no files found for recursive download
- Add detailed debug logging in getAllFilesRecursive() to track folder processing
- Log content count at each folder level to help diagnose issues
- Add DOWNLOAD_FOLDER_RECURSIVE action in FileAction
- Add action ID in ids.xml
- Add UI strings for recursive download confirmation dialogs
- Add showDownloadFolderRecursiveConfirmation() in FileActivity
- Add downloadFolderRecursive() method in FileOperationsHelper
- Add overloaded syncFile() method with recursive parameter
- FileDetailFragment: Add handler for action_sync_file_recursive to show recursive download dialog
- OCFileListFragment: Add handler for recursive download action in file list
- PreviewTextFileFragment: Add confirmation dialog for folder sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sync folders + subfolders

1 participant