desktop icon indicating copy to clipboard operation
desktop copied to clipboard

fix(vfs/cfapi): Preserve FILE_ATTRIBUTE_SYSTEM to prevent custom folder icons from being reset

Open hsachdeva9 opened this issue 2 weeks ago • 0 comments

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:

  1. A desktop.ini file inside the folder
  2. The FILE_ATTRIBUTE_SYSTEM attribute 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:

  1. updatePlaceholderState(): Added code to read and preserve existing file attributes before calling CfUpdatePlaceholder()

  2. createPlaceholderInfo(): Modified to check for existing file attributes before setting defaults

  3. 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]

hsachdeva9 avatar Dec 12 '25 01:12 hsachdeva9