文件更新后 CfSetInSyncState 失败并显示 ERROR_NOT_A_CLOUD_FILE [英] CfSetInSyncState fails with ERROR_NOT_A_CLOUD_FILE after a file update

查看:34
本文介绍了文件更新后 CfSetInSyncState 失败并显示 ERROR_NOT_A_CLOUD_FILE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用云镜像 示例 并且我在使用写字板应用程序编辑 .txt 文件后设置文件同步状态时遇到问题.当我尝试将文件同步状态设置为同步状态 (CF_IN_SYNC_STATE_IN_SYNC) 时,我收到错误 ERROR_NOT_A_CLOUD_FILE.但是当我使用记事本应用程序时,我可以成功地更改文件同步状态而不会出错.如果有人对此问题有一些建议并可以与我分享,我将不胜感激.

I am using the Cloud Mirror sample and I am having problems to set a file sync state after I edit a .txt file with WordPad app. When I try to set the file sync state to in sync state (CF_IN_SYNC_STATE_IN_SYNC) I am getting the error ERROR_NOT_A_CLOUD_FILE. But when I use the Notepad app I can change the file sync state successfully without errors. If anyone has some suggestions for this issue and can share it with me I will appreciate it.

推荐答案

经过一些测试并考虑到 Rita Han- MSFT 回答我无法设置文件重解析点,就像我在此 问题.但我可以使用 CfSetInSyncState使用 CfConvertToPlaceholder 函数没有错误再次将文件转换为占位符,因为在使用写字板等某些应用程序修改 txt 文件后,该文件不再是占位符.并检查文件是否是占位符我使用了 CfGetPlaceholderStateFromFindData 函数.代码是下一个:

After some tests and taking account the Rita Han - MSFT answer I couldn't set the file reparse point, like I posted in this question. But I can use the CfSetInSyncState without errors using the CfConvertToPlaceholder function to convert the file to a placeholder again, because after a txt file modification with some apps like WordPad the file isn't a placeholder anymore. And to check if the file is a placeholder I used the CfGetPlaceholderStateFromFindData function. The code was the next:

1- 获取占位符状态

    CF_PLACEHOLDER_STATE result = CF_PLACEHOLDER_STATE::CF_PLACEHOLDER_STATE_INVALID;
    WIN32_FIND_DATA findData;
    HANDLE hFileHandle = FindFirstFileEx(
        filePath.data(), // wstring with the file path
        FindExInfoStandard,
        &findData,
        FindExSearchNameMatch,
        NULL,
        FIND_FIRST_EX_ON_DISK_ENTRIES_ONLY);

    if (hFileHandle != INVALID_HANDLE_VALUE)
    {
        result = CfGetPlaceholderStateFromFindData(&findData); // Placeholder state
    }

2- 再次将文件转换为占位符

    HANDLE fileHandle = CreateFile(
        filePath.data(), // wstring with the file path
        WRITE_DAC,
        0,
        NULL,
        OPEN_EXISTING,
        FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT,
        NULL);

    if (fileHandle == INVALID_HANDLE_VALUE)
    {
        //Invalid handle
    }

    HRESULT hr = CfOpenFileWithOplock(filePath.c_str(), CF_OPEN_FILE_FLAGS::CF_OPEN_FILE_FLAG_EXCLUSIVE, &fileHandle);

    if (hr == S_OK)
    {
        LPCVOID fileIdentity = filePath.data();
        DWORD fileIdentityLength = (USHORT)(wcslen(filePath.data()) + 1) * sizeof(WCHAR);
        CF_CONVERT_FLAGS convertFlags = CF_CONVERT_FLAGS::CF_CONVERT_FLAG_MARK_IN_SYNC;
        USN* convertUsn = nullptr;
        LPOVERLAPPED overlapped = NULL;

        hr = CfConvertToPlaceholder(fileHandle, fileIdentity, fileIdentityLength, convertFlags, convertUsn, overlapped);

        if (hr == S_OK)
        {
            // The placeholder was converted successfully
        }

3- 更改文件状态

    HANDLE fileHandle;
    // filePath is a wstring with the file path
    HRESULT hr = CfOpenFileWithOplock(filePath.c_str(), CF_OPEN_FILE_FLAGS::CF_OPEN_FILE_FLAG_WRITE_ACCESS, &fileHandle);

    if (hr == S_OK)
    {
        hr = CfSetInSyncState(fileHandle, CF_IN_SYNC_STATE::CF_IN_SYNC_STATE_IN_SYNC, CF_SET_IN_SYNC_FLAGS::CF_SET_IN_SYNC_FLAG_NONE, NULL);

        if (hr == S_OK)
        {
            // The file state was changed successfully
        }

这篇关于文件更新后 CfSetInSyncState 失败并显示 ERROR_NOT_A_CLOUD_FILE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆