fix(vfs/cfapi): Preserve FILE_ATTRIBUTE_SYSTEM to prevent custom folder icons from being reset
Summary
- Fix custom Windows folder icons being reset during sync operations
- Preserve existing file attributes (especially
FILE_ATTRIBUTE_SYSTEM) when updating CFAPI placeholders
Fixes #9197
Problem
On Windows, custom folder icons are implemented using:
- A
desktop.inifile inside the folder - The
FILE_ATTRIBUTE_SYSTEMattribute set on the folder
When Nextcloud Desktop syncs folders, the CFAPI wrapper was resetting the FileAttributes field in CF_FS_METADATA to either FILE_ATTRIBUTE_NORMAL or FILE_ATTRIBUTE_DIRECTORY, causing the FILE_ATTRIBUTE_SYSTEM flag to be lost. This resulted in custom folder icons being reset to the default folder icon after every sync.
Solution
Before setting file attributes during CFAPI placeholder operations, the code now reads the current file attributes using GetFileAttributesW() and preserves them. This ensures that FILE_ATTRIBUTE_SYSTEM (and any other user-set attributes) are not lost during sync operations.
Changes made to src/libsync/vfs/cfapi/cfapiwrapper.cpp:
-
updatePlaceholderState(): Added code to read and preserve existing file attributes before callingCfUpdatePlaceholder() -
createPlaceholderInfo(): Modified to check for existing file attributes before setting defaults -
createPlaceholdersInfo(): Same fix applied to the batch placeholder creation function
Test plan
- [X] Set a custom icon on a folder inside the Nextcloud sync directory (Right-click → Properties → Customize → Change Icon)
- [X] Add or modify a file inside that folder to trigger a sync
- [X] Verify the custom folder icon is preserved after sync completes
- [X] Repeat the test multiple times to ensure consistency
Signed-off-by: hsachdeva9 [email protected]