-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix recursive folder sync #16602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix recursive folder sync #16602
Changes from all commits
a76e556
5d250e5
2b1a369
e8312d1
5ec53dc
f922366
76970ae
34f8ecd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ class FolderDownloadWorker( | |
| private const val TAG = "📂" + "FolderDownloadWorker" | ||
| const val FOLDER_ID = "FOLDER_ID" | ||
| const val ACCOUNT_NAME = "ACCOUNT_NAME" | ||
| const val RECURSIVE_DOWNLOAD = "RECURSIVE_DOWNLOAD" | ||
|
|
||
| private val pendingDownloads: MutableSet<Long> = ConcurrentHashMap.newKeySet<Long>() | ||
|
|
||
|
|
@@ -61,6 +62,8 @@ class FolderDownloadWorker( | |
| return Result.failure() | ||
| } | ||
|
|
||
| val recursiveDownload = inputData.getBoolean(RECURSIVE_DOWNLOAD, false) | ||
|
|
||
| val optionalUser = accountManager.getUser(accountName) | ||
| if (optionalUser.isEmpty) { | ||
| Log_OC.e(TAG, "failed user is not present") | ||
|
|
@@ -75,7 +78,7 @@ class FolderDownloadWorker( | |
| return Result.failure() | ||
| } | ||
|
|
||
| Log_OC.d(TAG, "🕒 started for ${user.accountName} downloading ${folder.fileName}") | ||
| Log_OC.d(TAG, "🕒 started for ${user.accountName} downloading ${folder.fileName} (recursive: $recursiveDownload)") | ||
|
|
||
| trySetForeground(folder) | ||
|
|
||
|
|
@@ -85,7 +88,13 @@ class FolderDownloadWorker( | |
|
|
||
| return withContext(Dispatchers.IO) { | ||
| try { | ||
| val files = getFiles(folder, storageManager) | ||
| val files = getFiles(folder, storageManager, recursiveDownload) | ||
|
|
||
| // Add warning log when no files found for recursive download | ||
| if (files.isEmpty()) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need warning log here? It is just extra info if file list is empty. Please change with info log and remove the emoji along with comment since Log already prints. |
||
| Log_OC.w(TAG, "⚠️ No files found for recursive download in folder: ${folder.fileName}") | ||
| } | ||
|
|
||
| val account = user.toOwnCloudAccount() | ||
| val client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(account, context) | ||
|
|
||
|
|
@@ -182,9 +191,40 @@ class FolderDownloadWorker( | |
| return file | ||
| } | ||
|
|
||
| private fun getFiles(folder: OCFile, storageManager: FileDataStorageManager): List<OCFile> = | ||
| storageManager.getFolderContent(folder, false) | ||
| .filter { !it.isFolder && !it.isDown } | ||
| private fun getFiles(folder: OCFile, storageManager: FileDataStorageManager, recursive: Boolean): List<OCFile> { | ||
| if (recursive) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please use Using Also, let’s remove the comments where possible. Ideally, the code should be self-explanatory and clear enough that extensive comments aren’t needed. |
||
| return getAllFilesRecursive(folder, storageManager) | ||
| } | ||
| // Use folder ID to avoid fileExists() check | ||
| return storageManager.getFolderContent(folder.fileId, false) | ||
| .filter { !it.isFolder } | ||
| } | ||
|
|
||
| /** | ||
| * Recursively get all files in the folder and its subfolders | ||
| */ | ||
| private fun getAllFilesRecursive(folder: OCFile, storageManager: FileDataStorageManager): List<OCFile> { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this and use |
||
| val result = mutableListOf<OCFile>() | ||
|
|
||
| // Use the folder ID directly to avoid fileExists() check that fails for subfolders not yet downloaded | ||
| val folderContent = storageManager.getFolderContent(folder.fileId, false) | ||
|
|
||
| Log_OC.d(TAG, "📂 getAllFilesRecursive: folder=${folder.fileName}, folderId=${folder.fileId}, contentCount=${folderContent.size}") | ||
|
|
||
| for (file in folderContent) { | ||
| if (!file.isFolder) { | ||
| // Add all files, regardless of download status, to ensure subfolders are synced | ||
| result.add(file) | ||
| } else { | ||
| Log_OC.d(TAG, "📂 Found subfolder: ${file.fileName}, recursing...") | ||
| // Recursively process subfolders | ||
| result.addAll(getAllFilesRecursive(file, storageManager)) | ||
| } | ||
| } | ||
|
|
||
| Log_OC.d(TAG, "📂 getAllFilesRecursive: returning ${result.size} files from folder ${folder.fileName}") | ||
| return result | ||
| } | ||
|
|
||
| private fun checkDiskSize(file: OCFile): Boolean { | ||
| val fileSizeInByte = file.fileLength | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR and your time.
I’d suggest keeping the scope of this PR strictly limited. The changes proposed outside of
FolderDownloadWorkerare quite significant and would require thorough testing.For now, let’s focus only on
FolderDownloadWorkerwith a minimal adjustment, for example, adding the new boolean parameter. From the UI side, we can introduce a separate action for this behavior, and have the worker that uses either the full nested structure or only the first-level depth based on that parameter.Keeping the scope small will help us review more effectively and move forward with confidence. Once this is merged and validated, we can discuss and plan the next steps separately.
Thanks for understanding and we can test, review other findings in separate PR.