From 0773ead45b353fafdc0d7ac93b77d78c939e30bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Gonz=C3=A1lez?= Date: Mon, 3 Mar 2025 20:06:33 +0100 Subject: [PATCH 1/5] feat: centrilize error message management and prevent to convert to placeholder folders --- include/sync_root_interface/Utilities.h | 1 + .../placeholders_interface/Planceholders.cpp | 62 +++++++------------ native-src/sync_root_interface/Utilities.cpp | 20 ++++++ 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/include/sync_root_interface/Utilities.h b/include/sync_root_interface/Utilities.h index f36df097..8164fdf2 100644 --- a/include/sync_root_interface/Utilities.h +++ b/include/sync_root_interface/Utilities.h @@ -11,6 +11,7 @@ class Utilities static std::wstring ProcessErrorNameToWString(_In_ ProcessErrorName error); static std::wstring FileOperationErrorToWString(_In_ FileOperationError error); static bool IsTemporaryFile(const std::wstring &fullPath); + static std::wstring GetErrorMessageCloudFiles(HRESULT hr); static winrt::com_array ConvertSidToStringSid(_In_ PSID sid) diff --git a/native-src/placeholders_interface/Planceholders.cpp b/native-src/placeholders_interface/Planceholders.cpp index ee851929..21c266c8 100644 --- a/native-src/placeholders_interface/Planceholders.cpp +++ b/native-src/placeholders_interface/Planceholders.cpp @@ -209,27 +209,28 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std: { if (!std::filesystem::exists(fullPath)) { - // El archivo no existe wprintf(L"[ConvertToPlaceholder] File does not exist\n"); return false; } - // Obtener un handle al archivo bool isDirectory = fs::is_directory(fullPath); - // Obtener un handle al archivo o carpeta + if (!isDirectory) { + wprintf(L"[ConvertToPlaceholder] File is not a directory\n"); + return false; + } + HANDLE fileHandle = CreateFileW( fullPath.c_str(), FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, - isDirectory ? FILE_FLAG_BACKUP_SEMANTICS : 0, // Agregar FILE_FLAG_BACKUP_SEMANTICS si es una carpeta + isDirectory ? FILE_FLAG_BACKUP_SEMANTICS : 0, nullptr); if (fileHandle == INVALID_HANDLE_VALUE) { - // Manejar el error al abrir el archivo wprintf(L"[ConvertToPlaceholder] Error opening file: %d\n", GetLastError()); return false; } @@ -238,7 +239,6 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std: USN convertUsn; OVERLAPPED overlapped = {}; - // Convierte la cadena de la identidad del servidor a LPCVOID LPCVOID idStrLPCVOID = static_cast(serverIdentity.c_str()); DWORD idStrByteLength = static_cast(serverIdentity.size() * sizeof(wchar_t)); @@ -246,33 +246,22 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std: if (FAILED(hr)) { - // Manejar el error al convertir a marcador de posición - wprintf(L"[ConvertToPlaceholder] Error converting to placeholder, ConvertToPlaceholder failed with HRESULT 0x%X\n", hr); - - // Puedes obtener información detallada sobre el error usando FormatMessage - LPVOID errorMsg; - FormatMessageW( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - hr, - 0, // Default language - (LPWSTR)&errorMsg, - 0, - NULL); - - wprintf(L"[ConvertToPlaceholder] Error details: %s\n", errorMsg); - - // Liberar el buffer de mensaje de error - LocalFree(errorMsg); - + std::wstring errorMessage = Utilities::GetErrorMessageCloudFiles(hr); + wprintf(L"[ConvertToPlaceholder] Error converting to placeholder, HRESULT: 0x%X\nDetails: %s\n", hr, errorMessage.c_str()); CloseHandle(fileHandle); - return false; } if (!isDirectory) { - CfSetPinState(fileHandle, CF_PIN_STATE_PINNED, CF_SET_PIN_FLAG_NONE, nullptr); + HRESULT hrPinState = CfSetPinState(fileHandle, CF_PIN_STATE_PINNED, CF_SET_PIN_FLAG_NONE, nullptr); + if (FAILED(hrPinState)) + { + std::wstring errorMessage = Utilities::GetErrorMessageCloudFiles(hrPinState); + wprintf(L"[ConvertToPlaceholder] Error setting pin state, HRESULT: 0x%X\nDetails: %s\n", hrPinState, errorMessage.c_str()); + CloseHandle(fileHandle); + return false; + } } CloseHandle(fileHandle); @@ -372,20 +361,11 @@ void Placeholders::UpdateFileIdentity(const std::wstring &filePath, const std::w if (FAILED(hr)) { - wprintf(L"[UpdateFileIdentity] Error updating fileIdentity: 0x%08X\n", hr); - LPWSTR errorMessage = nullptr; - FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, - HRESULT_CODE(hr), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - reinterpret_cast(&errorMessage), - 0, - nullptr); - if (errorMessage) - { - wprintf(L"[UpdateFileIdentity] Error: %ls\n", errorMessage); - LocalFree(errorMessage); - } + std::wstring errorMessage = Utilities::GetErrorMessageCloudFiles(hr); + wprintf(L"[UpdateFileIdentity] Error updating fileIdentity: %ls\n", errorMessage.c_str()); + CloseHandle(fileHandle); + return; + } CloseHandle(fileHandle); diff --git a/native-src/sync_root_interface/Utilities.cpp b/native-src/sync_root_interface/Utilities.cpp index fa664e3b..1f1e9ada 100644 --- a/native-src/sync_root_interface/Utilities.cpp +++ b/native-src/sync_root_interface/Utilities.cpp @@ -160,6 +160,26 @@ void Utilities::ApplyTransferStateToFile(_In_ PCWSTR fullPath, _In_ CF_CALLBACK_ } } +std::wstring Utilities::GetErrorMessageCloudFiles(HRESULT hr) { + LPWSTR errorMsg = nullptr; + DWORD size = FormatMessageW( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, + hr, + 0, + (LPWSTR)&errorMsg, + 0, + nullptr + ); + + std::wstring message; + if (size > 0 && errorMsg != nullptr) { + message.assign(errorMsg, size); + } + LocalFree(errorMsg); + return message; +} + bool Utilities::IsTemporaryFile(const std::wstring &fullPath) { From af4d00a4ff64598018ec80d63ce89c3931091694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Gonz=C3=A1lez?= Date: Mon, 14 Apr 2025 13:23:19 +0200 Subject: [PATCH 2/5] feat: add active shell update in UpdateSyncStatus --- .../placeholders_interface/Planceholders.cpp | 92 ++++++++++++++----- 1 file changed, 68 insertions(+), 24 deletions(-) diff --git a/native-src/placeholders_interface/Planceholders.cpp b/native-src/placeholders_interface/Planceholders.cpp index 20346922..81def8a6 100644 --- a/native-src/placeholders_interface/Planceholders.cpp +++ b/native-src/placeholders_interface/Planceholders.cpp @@ -274,34 +274,78 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std: */ void Placeholders::UpdateSyncStatus(const std::wstring &filePath, bool inputSyncState, bool isDirectory = false) { - wprintf(L"[UpdateSyncStatus] Path: %ls\n", filePath.c_str()); - HANDLE fileHandle = CreateFileW( - filePath.c_str(), - FILE_WRITE_ATTRIBUTES, // permisson needed to change the state - FILE_SHARE_READ | FILE_SHARE_WRITE, - nullptr, - OPEN_EXISTING, - isDirectory ? FILE_FLAG_BACKUP_SEMANTICS : FILE_ATTRIBUTE_NORMAL, - nullptr); - - if (fileHandle == INVALID_HANDLE_VALUE) + try { - wprintf(L"[UpdateSyncStatus] Error al abrir el archivo: %d\n", GetLastError()); - return; - } + // Get a handle to the file + HANDLE hFile = CreateFileW( + filePath.c_str(), + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + nullptr, + OPEN_EXISTING, + isDirectory ? FILE_FLAG_BACKUP_SEMANTICS : 0, + nullptr); - // https://learn.microsoft.com/en-us/windows/win32/api/cfapi/nf-cfapi-cfsetinsyncstate - // https://learn.microsoft.com/en-us/windows/win32/api/cfapi/ne-cfapi-cf_in_sync_state - CF_IN_SYNC_STATE syncState = inputSyncState ? CF_IN_SYNC_STATE_IN_SYNC : CF_IN_SYNC_STATE_NOT_IN_SYNC; - // wprintf(L"Marking item as %s: %ls\n", inputSyncState ? L"IN_SYNC" : L"NOT_IN_SYNC", filePath.c_str()); - HRESULT hr = CfSetInSyncState(fileHandle, syncState, CF_SET_IN_SYNC_FLAG_NONE, nullptr); - // imprimir hresult - if (FAILED(hr)) + if (hFile == INVALID_HANDLE_VALUE) + { + wprintf(L"[UpdateSyncStatus] Failed to open file %s with error %d\n", filePath.c_str(), GetLastError()); + return; + } + + // Set the sync state using Cloud Files API + HRESULT hr = CfSetInSyncState( + hFile, + inputSyncState ? CF_IN_SYNC_STATE_IN_SYNC : CF_IN_SYNC_STATE_NOT_IN_SYNC, + CF_SET_IN_SYNC_FLAG_NONE, + nullptr); + + if (FAILED(hr)) + { + wprintf(L"[UpdateSyncStatus] Failed to set sync state for %s with HRESULT 0x%08x\n", filePath.c_str(), hr); + CloseHandle(hFile); + return; + } + + // Update property store to reflect sync state + winrt::com_ptr shellItem; + hr = SHCreateItemFromParsingName(filePath.c_str(), nullptr, __uuidof(shellItem), shellItem.put_void()); + + if (SUCCEEDED(hr)) + { + winrt::com_ptr propStore; + hr = shellItem->GetPropertyStore(GETPROPERTYSTOREFLAGS::GPS_READWRITE, __uuidof(propStore), propStore.put_void()); + + if (SUCCEEDED(hr)) + { + PROPVARIANT syncState; + InitPropVariantFromBoolean(inputSyncState, &syncState); + propStore->SetValue(PKEY_StorageProviderState, syncState); + propStore->Commit(); + } + } + + // Notify shell of changes + SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, filePath.c_str(), nullptr); + + // Also notify parent directory + std::wstring parentPath = filePath; + size_t lastSlash = parentPath.find_last_of(L'\\'); + if (lastSlash != std::wstring::npos) { + parentPath = parentPath.substr(0, lastSlash); + SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH, parentPath.c_str(), nullptr); + } + + CloseHandle(hFile); + wprintf(L"[UpdateSyncStatus] Successfully updated sync state for %s to %s\n", + filePath.c_str(), + inputSyncState ? L"IN_SYNC" : L"NOT_IN_SYNC"); + } + catch (...) { - wprintf(L"[UpdateSyncStatus] Error al establecer el estado de sincronización: %ld\n", hr); + wprintf(L"[UpdateSyncStatus] Failed to update sync state for %s with error %08x\n", + filePath.c_str(), + static_cast(winrt::to_hresult())); } - - CloseHandle(fileHandle); } void Placeholders::UpdateFileIdentity(const std::wstring &filePath, const std::wstring &fileIdentity, bool isDirectory) From a081a0068e9d3cfc1821e8da67b4a3f3d2a0f035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Gonz=C3=A1lez?= Date: Tue, 15 Apr 2025 13:15:33 +0200 Subject: [PATCH 3/5] wip --- .../placeholders_interface/Planceholders.cpp | 92 +++++-------------- 1 file changed, 24 insertions(+), 68 deletions(-) diff --git a/native-src/placeholders_interface/Planceholders.cpp b/native-src/placeholders_interface/Planceholders.cpp index f8ed5990..7c8ede08 100644 --- a/native-src/placeholders_interface/Planceholders.cpp +++ b/native-src/placeholders_interface/Planceholders.cpp @@ -281,78 +281,34 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std: */ void Placeholders::UpdateSyncStatus(const std::wstring &filePath, bool inputSyncState, bool isDirectory = false) { - try - { - // Get a handle to the file - HANDLE hFile = CreateFileW( - filePath.c_str(), - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - nullptr, - OPEN_EXISTING, - isDirectory ? FILE_FLAG_BACKUP_SEMANTICS : 0, - nullptr); - - if (hFile == INVALID_HANDLE_VALUE) - { - wprintf(L"[UpdateSyncStatus] Failed to open file %s with error %d\n", filePath.c_str(), GetLastError()); - return; - } - - // Set the sync state using Cloud Files API - HRESULT hr = CfSetInSyncState( - hFile, - inputSyncState ? CF_IN_SYNC_STATE_IN_SYNC : CF_IN_SYNC_STATE_NOT_IN_SYNC, - CF_SET_IN_SYNC_FLAG_NONE, - nullptr); - - if (FAILED(hr)) - { - wprintf(L"[UpdateSyncStatus] Failed to set sync state for %s with HRESULT 0x%08x\n", filePath.c_str(), hr); - CloseHandle(hFile); - return; - } - - // Update property store to reflect sync state - winrt::com_ptr shellItem; - hr = SHCreateItemFromParsingName(filePath.c_str(), nullptr, __uuidof(shellItem), shellItem.put_void()); - - if (SUCCEEDED(hr)) - { - winrt::com_ptr propStore; - hr = shellItem->GetPropertyStore(GETPROPERTYSTOREFLAGS::GPS_READWRITE, __uuidof(propStore), propStore.put_void()); - - if (SUCCEEDED(hr)) - { - PROPVARIANT syncState; - InitPropVariantFromBoolean(inputSyncState, &syncState); - propStore->SetValue(PKEY_StorageProviderState, syncState); - propStore->Commit(); - } - } - - // Notify shell of changes - SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, filePath.c_str(), nullptr); - - // Also notify parent directory - std::wstring parentPath = filePath; - size_t lastSlash = parentPath.find_last_of(L'\\'); - if (lastSlash != std::wstring::npos) { - parentPath = parentPath.substr(0, lastSlash); - SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH, parentPath.c_str(), nullptr); - } + wprintf(L"[UpdateSyncStatus] Path: %ls\n", filePath.c_str()); + HANDLE fileHandle = CreateFileW( + filePath.c_str(), + FILE_WRITE_ATTRIBUTES, // permisson needed to change the state + FILE_SHARE_READ | FILE_SHARE_WRITE, + nullptr, + OPEN_EXISTING, + isDirectory ? FILE_FLAG_BACKUP_SEMANTICS : FILE_ATTRIBUTE_NORMAL, + nullptr); - CloseHandle(hFile); - wprintf(L"[UpdateSyncStatus] Successfully updated sync state for %s to %s\n", - filePath.c_str(), - inputSyncState ? L"IN_SYNC" : L"NOT_IN_SYNC"); + if (fileHandle == INVALID_HANDLE_VALUE) + { + wprintf(L"[UpdateSyncStatus] Error al abrir el archivo: %d\n", GetLastError()); + return; } - catch (...) + + // https://learn.microsoft.com/en-us/windows/win32/api/cfapi/nf-cfapi-cfsetinsyncstate + // https://learn.microsoft.com/en-us/windows/win32/api/cfapi/ne-cfapi-cf_in_sync_state + CF_IN_SYNC_STATE syncState = inputSyncState ? CF_IN_SYNC_STATE_IN_SYNC : CF_IN_SYNC_STATE_NOT_IN_SYNC; + // wprintf(L"Marking item as %s: %ls\n", inputSyncState ? L"IN_SYNC" : L"NOT_IN_SYNC", filePath.c_str()); + HRESULT hr = CfSetInSyncState(fileHandle, syncState, CF_SET_IN_SYNC_FLAG_NONE, nullptr); + // imprimir hresult + if (FAILED(hr)) { - wprintf(L"[UpdateSyncStatus] Failed to update sync state for %s with error %08x\n", - filePath.c_str(), - static_cast(winrt::to_hresult())); + wprintf(L"[UpdateSyncStatus] Error al establecer el estado de sincronización: %ld\n", hr); } + + CloseHandle(fileHandle); } void Placeholders::UpdateFileIdentity(const std::wstring &filePath, const std::wstring &fileIdentity, bool isDirectory) From 993cc9fc043226c9e621f220bfef5da81397e28f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Gonz=C3=A1lez?= Date: Wed, 16 Apr 2025 20:35:05 +0200 Subject: [PATCH 4/5] feat: refactor update sync status --- .../placeholders_interface/Planceholders.cpp | 115 ++++++++++++++---- 1 file changed, 91 insertions(+), 24 deletions(-) diff --git a/native-src/placeholders_interface/Planceholders.cpp b/native-src/placeholders_interface/Planceholders.cpp index 7c8ede08..e9d6a940 100644 --- a/native-src/placeholders_interface/Planceholders.cpp +++ b/native-src/placeholders_interface/Planceholders.cpp @@ -193,13 +193,10 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std: return false; } + // print fullPath + wprintf(L"[ConvertToPlaceholder] Full path: %ls\n", fullPath.c_str()); bool isDirectory = fs::is_directory(fullPath); - if (!isDirectory) { - wprintf(L"[ConvertToPlaceholder] File is not a directory\n"); - return false; - } - HANDLE fileHandle = CreateFileW( fullPath.c_str(), FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, @@ -273,42 +270,112 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std: } } +// Función para obtener el mensaje de error de HRESULT +std::wstring GetErrorMessageFromHRESULT(HRESULT hr) +{ + LPWSTR errorMessage = nullptr; + DWORD result = FormatMessageW( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, + hr, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + reinterpret_cast(&errorMessage), + 0, + nullptr); + + std::wstring message; + if (result > 0 && errorMessage) + { + message = errorMessage; + LocalFree(errorMessage); + } + else + { + message = L"Error desconocido"; + } + + return message; +} + /** * @brief Mark a file or directory as synchronized * @param filePath path to the file or directory * @param isDirectory true if the path is a directory, false if it is a file * @return void */ -void Placeholders::UpdateSyncStatus(const std::wstring &filePath, bool inputSyncState, bool isDirectory = false) +void Placeholders::UpdateSyncStatus(const std::wstring &filePath, + bool inputSyncState, + bool isDirectory /* = false */) { wprintf(L"[UpdateSyncStatus] Path: %ls\n", filePath.c_str()); - HANDLE fileHandle = CreateFileW( - filePath.c_str(), - FILE_WRITE_ATTRIBUTES, // permisson needed to change the state - FILE_SHARE_READ | FILE_SHARE_WRITE, - nullptr, - OPEN_EXISTING, - isDirectory ? FILE_FLAG_BACKUP_SEMANTICS : FILE_ATTRIBUTE_NORMAL, - nullptr); - if (fileHandle == INVALID_HANDLE_VALUE) + CF_PLACEHOLDER_STATE state = GetPlaceholderState(filePath); + if (state == CF_PLACEHOLDER_STATE_INVALID) + { + if (!ConvertToPlaceholder(filePath, L"temp_identity")) + { + wprintf(L"[UpdateSyncStatus] ‑ no se pudo convertir a placeholder\n"); + return; + } + } + + + DWORD flags = FILE_FLAG_OPEN_REPARSE_POINT; + if (isDirectory) flags |= FILE_FLAG_BACKUP_SEMANTICS; + + HANDLE h = CreateFileW(filePath.c_str(), + FILE_WRITE_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + nullptr, + OPEN_EXISTING, + flags, + nullptr); + + if (h == INVALID_HANDLE_VALUE) { - wprintf(L"[UpdateSyncStatus] Error al abrir el archivo: %d\n", GetLastError()); + wprintf(L"[UpdateSyncStatus] CreateFileW falló: %lu\n", GetLastError()); return; } - // https://learn.microsoft.com/en-us/windows/win32/api/cfapi/nf-cfapi-cfsetinsyncstate - // https://learn.microsoft.com/en-us/windows/win32/api/cfapi/ne-cfapi-cf_in_sync_state - CF_IN_SYNC_STATE syncState = inputSyncState ? CF_IN_SYNC_STATE_IN_SYNC : CF_IN_SYNC_STATE_NOT_IN_SYNC; - // wprintf(L"Marking item as %s: %ls\n", inputSyncState ? L"IN_SYNC" : L"NOT_IN_SYNC", filePath.c_str()); - HRESULT hr = CfSetInSyncState(fileHandle, syncState, CF_SET_IN_SYNC_FLAG_NONE, nullptr); - // imprimir hresult + CF_IN_SYNC_STATE sync = inputSyncState ? CF_IN_SYNC_STATE_IN_SYNC + : CF_IN_SYNC_STATE_NOT_IN_SYNC; + + HRESULT hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr); + if (FAILED(hr)) { - wprintf(L"[UpdateSyncStatus] Error al establecer el estado de sincronización: %ld\n", hr); + switch (HRESULT_CODE(hr)) + { + case ERROR_RETRY: + Sleep(50); + hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr); + wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n"); + break; + + case ERROR_CLOUD_FILE_PROVIDER_NOT_RUNNING: // 0x1A94 + SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, filePath.c_str(), nullptr); + wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n"); + break; + + case ERROR_CLOUD_FILE_NOT_IN_SYNC: + ConvertToPlaceholder(filePath, L"temp_identity"); + hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr); + wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n"); + break; + + default: + wprintf(L"[UpdateSyncStatus] CfSetInSyncState 0x%08X\n", hr); + break; + } + } + else + { + wprintf(L"[UpdateSyncStatus] Estado actualizado\n"); } - CloseHandle(fileHandle); + CloseHandle(h); + + SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, filePath.c_str(), nullptr); } void Placeholders::UpdateFileIdentity(const std::wstring &filePath, const std::wstring &fileIdentity, bool isDirectory) From d10e7725f8e5de87e69483d0beafc66c95686423 Mon Sep 17 00:00:00 2001 From: ArceDanielShok Date: Thu, 24 Apr 2025 13:42:03 -0300 Subject: [PATCH 5/5] fix: update version to 1.0.10 in package.json --- .../placeholders_interface/Planceholders.cpp | 70 +++---------------- package.json | 2 +- 2 files changed, 10 insertions(+), 62 deletions(-) diff --git a/native-src/placeholders_interface/Planceholders.cpp b/native-src/placeholders_interface/Planceholders.cpp index 0fa21997..ea5c07c2 100644 --- a/native-src/placeholders_interface/Planceholders.cpp +++ b/native-src/placeholders_interface/Planceholders.cpp @@ -49,7 +49,7 @@ void Placeholders::CreateOne( { Placeholders::ConvertToPlaceholder(fullPath, fileIdentity); Placeholders::MaintainIdentity(fullPath, fileIdentity, false); - return; // No hacer nada si ya existe + return; } std::wstring relativeName(fileIdentity); @@ -193,7 +193,6 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std: return false; } - // print fullPath wprintf(L"[ConvertToPlaceholder] Full path: %ls\n", fullPath.c_str()); bool isDirectory = fs::is_directory(fullPath); @@ -271,7 +270,6 @@ bool Placeholders::ConvertToPlaceholder(const std::wstring &fullPath, const std: } } -// Función para obtener el mensaje de error de HRESULT std::wstring GetErrorMessageFromHRESULT(HRESULT hr) { LPWSTR errorMessage = nullptr; @@ -305,24 +303,14 @@ std::wstring GetErrorMessageFromHRESULT(HRESULT hr) * @return void */ void Placeholders::UpdateSyncStatus(const std::wstring &filePath, - bool inputSyncState, - bool isDirectory /* = false */) + bool inputSyncState, + bool isDirectory /* = false */) { wprintf(L"[UpdateSyncStatus] Path: %ls\n", filePath.c_str()); - CF_PLACEHOLDER_STATE state = GetPlaceholderState(filePath); - if (state == CF_PLACEHOLDER_STATE_INVALID) - { - if (!ConvertToPlaceholder(filePath, L"temp_identity")) - { - wprintf(L"[UpdateSyncStatus] ‑ no se pudo convertir a placeholder\n"); - return; - } - } - - - DWORD flags = FILE_FLAG_OPEN_REPARSE_POINT; - if (isDirectory) flags |= FILE_FLAG_BACKUP_SEMANTICS; + DWORD flags = FILE_FLAG_OPEN_REPARSE_POINT; + if (isDirectory) + flags |= FILE_FLAG_BACKUP_SEMANTICS; HANDLE h = CreateFileW(filePath.c_str(), FILE_WRITE_ATTRIBUTES, @@ -347,18 +335,18 @@ void Placeholders::UpdateSyncStatus(const std::wstring &filePath, { switch (HRESULT_CODE(hr)) { - case ERROR_RETRY: + case ERROR_RETRY: Sleep(50); hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr); wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n"); break; - case ERROR_CLOUD_FILE_PROVIDER_NOT_RUNNING: // 0x1A94 + case ERROR_CLOUD_FILE_PROVIDER_NOT_RUNNING: // 0x1A94 SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, filePath.c_str(), nullptr); wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n"); break; - case ERROR_CLOUD_FILE_NOT_IN_SYNC: + case ERROR_CLOUD_FILE_NOT_IN_SYNC: ConvertToPlaceholder(filePath, L"temp_identity"); hr = CfSetInSyncState(h, sync, CF_SET_IN_SYNC_FLAG_NONE, nullptr); wprintf(L"[UpdateSyncStatus] Retry CfSetInSyncState\n"); @@ -428,33 +416,9 @@ void Placeholders::UpdateFileIdentity(const std::wstring &filePath, const std::w wprintf(L"[UpdateFileIdentity] Error updating fileIdentity: %ls\n", errorMessage.c_str()); CloseHandle(fileHandle); return; - - } - - CloseHandle(fileHandle); -} - -CF_PLACEHOLDER_STATE Placeholders::GetPlaceholderState(const std::wstring &filePath) -{ - HANDLE fileHandle = CreateFileW(filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); - if (fileHandle == INVALID_HANDLE_VALUE) - { - // Error al abrir el archivo - return CF_PLACEHOLDER_STATE_INVALID; - } - - FILE_BASIC_INFO fileBasicInfo; - if (!GetFileInformationByHandleEx(fileHandle, FileBasicInfo, &fileBasicInfo, sizeof(fileBasicInfo))) - { - // Error al obtener la información básica del archivo - CloseHandle(fileHandle); - return CF_PLACEHOLDER_STATE_INVALID; } - CF_PLACEHOLDER_STATE placeholderState = CfGetPlaceholderStateFromFileInfo(&fileBasicInfo, FileBasicInfo); CloseHandle(fileHandle); - - return placeholderState; } std::string Placeholders::GetFileIdentity(const std::wstring &filePath) @@ -479,22 +443,6 @@ std::string Placeholders::GetFileIdentity(const std::wstring &filePath) } } -CF_PLACEHOLDER_STATE GetPlaceholderStateMock(const std::wstring &filePath) -{ - static std::random_device rd; - static std::mt19937 gen(rd()); - static std::uniform_int_distribution dis(0, 1); - - if (dis(gen) == 0) - { - return CF_PLACEHOLDER_STATE_IN_SYNC; - } - else - { - return CF_PLACEHOLDER_STATE_SYNC_ROOT; - } -} - FileState Placeholders::GetPlaceholderInfo(const std::wstring &directoryPath) { diff --git a/package.json b/package.json index de1c7c72..eaf05714 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@internxt/node-win", - "version": "1.0.9", + "version": "1.0.10", "description": "Drive desktop node addon", "main": "dist/index.ts", "types": "dist/index.d.ts",