How to update pinned file (cfapi)?

WebDAV 21 Reputation points
2020-08-18T04:29:36.543+00:00

I am using the Cloud Files API. Here is my scenario:

  1. Files are synchronized from server to client.
  2. One file is pinned.
  3. The pinned file is changed on the server.
  4. The server notifies the client that the pinned file is modified.

Now how do I update the pinned file content? Do I dehydrate it or use any other API to update the content?

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,498 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Fei Xue - MSFT 1,111 Reputation points
    2020-09-02T08:22:13.99+00:00

    Here is the answer for the following questions, please feel to let me know if you still have the problem.

    Questions 1:

    I have implemented CF_CALLBACK_TYPE_FETCH_PLACEHOLDERS callback and CF_CALLBACK_TYPE_FETCH_DATA callback using Cloud Files Windows API and it is working well. Files sync from server to client properly.

    Now at some point a file is modified on the server. How do I properly mark it as not in sync on the client?
    Should I directly call the CfSetInSyncState() function?
    Do I dehydrate the placeholder manually on the client using CfUpdatePlaceholder() or is it automatic?
    What is the role of StorageProviderSyncRootInfo.InSyncPolicy in this process?

    Answer 1:

    Both CfSetInSyncState and CfUpdatePlaceholder can be used to mark something as insync or not insync.

    However, usually a sync engine does not need to do so explicitly. The filter takes care of the insync state as a result of the local FS changes. For changes in the cloud, the sync engine usually just goes ahead and applies the changes without toggling the insync state. In fact, I would recommend sync engines never clearing insync. This can cause confusion after a crash because now the sync engine can’t easily tell why the file is not in-sync: was it because the user modified the file? Or was it because the sync engine cleared the in-sync bit itself before the crash? Different actions would be needed for either case. Conceptually, the in-sync state should be interpreted as “is there any data that hasn’t been uploaded to the cloud yet?”

    Question 2:

    How to update pinned file (cfapi)?
    I am using the Cloud Files API. Here is my scenario:

    1. Files are synchronized from server to client.
    2. One file is pinned.
    3. The pinned file is changed on the server.
    4. The server notifies the client that the pinned file is modified.

    Now how do I update the pinned file content? Do I dehydrate it or use any other API to update the content?

    Answer 2:

    There may be different ways of implementing this depending on what the provider wants to achieve. Provider may need to synchronize some aspects of the operation as well. Also, there is no Cf API available to merge contents.

    An easy way would be to download the modified content locally into a temp file, rename the temp file onto the PINNED file (delete it first if needed), setting the pinned state and converting it back to a placeholder while marking it in-sync. Another way could be to overwrite the file with new content and then convert it back to placeholder and PINNED. The provider needs to figure what’s best and consider issues like what happens during a crash. There are also file system directory change notifications that could be used in various capacities.

    0 comments No comments

  2. WebDAV 106 Reputation points
    2020-09-09T02:10:57.307+00:00

    Thank you for the explanation. I just wanted to indicate that downloading into a temp file or overwriting existing file outside of callbacks has the following issues:

    1. No progress is displayed. There is no way to report progress using CfReportProviderProgress() because it requires ConnectionKey and TransferKey that are available in callbacks only.
    2. No validation is performed inside CF_CALLBACK_TYPE_VALIDATE_DATA callback. Not sure if I understand validation correctly, but looks like the file does not go through the validation process in this case.
    3. A user does not have any information that the file is being modified on the server and the update is pending (we can not mark it as not in-sync on the client and there is no way to change the default set of icons). I guess the only way would be to add an additional custom icon indicating the "download pending" state next to the regular icon, see here.