|
15 | 15 | #include <cctype> |
16 | 16 | #include <windows.h> |
17 | 17 | #include <shlobj.h> |
| 18 | +#include "convert_to_placeholder.h" |
18 | 19 |
|
19 | 20 | using namespace std; |
20 | 21 |
|
@@ -61,40 +62,6 @@ void Placeholders::MaintainIdentity(std::wstring &fullPath, PCWSTR itemIdentity, |
61 | 62 | } |
62 | 63 | } |
63 | 64 |
|
64 | | -void Placeholders::ConvertToPlaceholder(const std::wstring &path, const std::wstring &placeholderId) |
65 | | -{ |
66 | | - bool isDirectory = fs::is_directory(path); |
67 | | - |
68 | | - winrt::file_handle fileHandle{CreateFileW( |
69 | | - path.c_str(), |
70 | | - FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, |
71 | | - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
72 | | - nullptr, |
73 | | - OPEN_EXISTING, |
74 | | - isDirectory ? FILE_FLAG_BACKUP_SEMANTICS : 0, |
75 | | - nullptr)}; |
76 | | - |
77 | | - if (!fileHandle) |
78 | | - { |
79 | | - throw std::runtime_error("Failed to open file: " + std::to_string(GetLastError())); |
80 | | - } |
81 | | - |
82 | | - CF_CONVERT_FLAGS convertFlags = CF_CONVERT_FLAG_MARK_IN_SYNC; |
83 | | - USN convertUsn; |
84 | | - OVERLAPPED overlapped = {}; |
85 | | - |
86 | | - LPCVOID idStrLPCVOID = static_cast<LPCVOID>(placeholderId.c_str()); |
87 | | - DWORD idStrByteLength = static_cast<DWORD>(placeholderId.size() * sizeof(wchar_t)); |
88 | | - |
89 | | - HRESULT hr = CfConvertToPlaceholder(fileHandle.get(), idStrLPCVOID, idStrByteLength, convertFlags, &convertUsn, &overlapped); |
90 | | - |
91 | | - // Only throw if it's not "already a placeholder" error |
92 | | - if (hr != 0x8007017C) |
93 | | - { |
94 | | - winrt::check_hresult(hr); |
95 | | - } |
96 | | -} |
97 | | - |
98 | 65 | /** |
99 | 66 | * @brief Mark a file or directory as synchronized |
100 | 67 | * @param filePath path to the file or directory |
@@ -147,7 +114,7 @@ void Placeholders::UpdateSyncStatus(const std::wstring &filePath, |
147 | 114 | break; |
148 | 115 |
|
149 | 116 | case ERROR_CLOUD_FILE_NOT_IN_SYNC: |
150 | | - ConvertToPlaceholder(filePath, L"temp_identity"); |
| 117 | + convert_to_placeholder(filePath, L"temp_identity"); |
151 | 118 | hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr); |
152 | 119 | wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n"); |
153 | 120 | break; |
|
0 commit comments