CfSetInSyncState() always fails if USN parameter is specified (cfapi)

WebDAV 106 Reputation points
2021-12-11T06:25:50.933+00:00

Calling the CfSetInSyncState() function always returns 0x80070179 "ERROR_CLOUD_FILE_NOT_IN_SYNC" if a USN parameter is specified. Regardless of the USN being passed, except for 0 or null.

The correct behaviour of the CfSetInSyncState() with USN is critical for us, because we do the following sequence in our app:

  1. We read USN before the file being sent from the client to the server.
  2. Send file content from the client to the server.
  3. Mark file as in-sync by calling CfSetInSyncState() with the USN read in step 1.

We can not just call CfSetInSyncState() with USN=0, because the file content may be modified on the client, between steps 2 and 3. This may result in changes being lost.

We also can not block the file for modifications when sending content to server - the file must be available for modifications by applications.

The issue with a sample code is described here: https://stackoverflow.com/questions/60816543/cfsetinsyncstate-does-not-behave-as-documented-cfapi

Is it a cfapi bug? And when it will be fixed?

@Rita Han - MSFT @Xiaopo Yang - MSFT

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,729 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
    2021-12-13T06:41:16.8+00:00

    RitaHan almost describe all CfSetInSyncState behavior. And

    I would expect that the first block (setting non sync file to sync) would not fail, since the USN did not changed before the cfSetInSyncState call. (This is what currently blocks me)

    As CfSetInSyncState showed, the USN* parameter is InSync-Usn. So This parameter needs to be a NULL pointer for NOT_IN_SYNC.

    We can not just call CfSetInSyncState() with USN=0, because the file content may be modified on the client, between steps 2 and 3. This may result in changes being lost.

    Why does this result in changes being lost? The previous read USN is not the same as USN generated by the modified file content. Isn‘t It developer’s duty to Hydrate based on some criteria(USN)? May you need CfUpdatePlaceholder(UpdateUsn)?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.