diff --git a/.github/workflows/check-pr-size.yml b/.github/workflows/check-pr-size.yml deleted file mode 100644 index 6289183a..00000000 --- a/.github/workflows/check-pr-size.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Check PR size - -on: - pull_request: - -jobs: - check_pr_size: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Calculate changed lines - id: diff_check - run: | - # Get the target branch commit (base) and the PR branch commit (head) - BASE_SHA="${{ github.event.pull_request.base.sha }}" - HEAD_SHA="${{ github.event.pull_request.head.sha }}" - echo "Base SHA: $BASE_SHA" - echo "Head SHA: $HEAD_SHA" - - # Compute the merge base between the two branches - MERGE_BASE=$(git merge-base "$HEAD_SHA" "$BASE_SHA") - echo "Merge Base: $MERGE_BASE" - - # Calculate added and deleted lines between the merge base and the head commit - TOTAL_CHANGED=$(git diff --numstat "$MERGE_BASE" "$HEAD_SHA" \ - | grep -v "yarn.lock" \ - | awk '{ added += $1; deleted += $2 } END { print added + deleted }') - - # Default to 0 if nothing is output - TOTAL_CHANGED=${TOTAL_CHANGED:-0} - echo "Total changed lines: $TOTAL_CHANGED" - - # Make the total available for later steps - echo "total=$TOTAL_CHANGED" >> "$GITHUB_OUTPUT" - - - name: Fail if too many changes - if: ${{ steps.diff_check.outputs.total > 500 }} - run: | - echo "PR has ${{ steps.diff_check.outputs.total }} changed lines, which exceeds the 500-line limit." - echo "Please reduce the size of this PR." - exit 1 diff --git a/README.md b/README.md index 49ce0a31..1b4cf2bc 100644 --- a/README.md +++ b/README.md @@ -1,34 +1 @@ -[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/internxt/node-win) - -# Setup - -This guide explains how to set up and build the `node-win` project. - -## Prerequisites - -Before proceeding, ensure you have the following tools installed: - -- **Python 3.10** -- **Node 20** - -```bash -nvm install 20 -``` - -- **node-gyp** - -```bash -npm install -g node-gyp -``` - -- **Visual Studio** (not VS Code) for building native dependencies. - -## Build Steps - -Run the following command to build the project: - -```bash -npm run build -``` - -This step compiles the necessary native bindings. +[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/internxt/node-win) \ No newline at end of file diff --git a/binding.gyp b/binding.gyp index c929117f..f03368d2 100644 --- a/binding.gyp +++ b/binding.gyp @@ -26,8 +26,6 @@ "native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp", "native-src/sync_root_interface/callbacks/FetchData/FileCopierWithProgress.cpp", "native-src/sync_root_interface/callbacks/FetchData/TransferContext.cpp", - "native-src/sync_root_interface/callbacks/FetchPlaceholder/FetchPlaceholder.cpp", - "native-src/sync_root_interface/callbacks/NotifyDelete/NotifyDeleteCallback.cpp", "native-src/virtual_drive/Wrappers.cpp" ], "include_dirs": [ diff --git a/dist/addon.node b/dist/addon.node index 60df547f..030c589c 100644 Binary files a/dist/addon.node and b/dist/addon.node differ diff --git a/include/placeholders_interface/Placeholders.h b/include/placeholders_interface/Placeholders.h index b557a13c..fabf37ae 100644 --- a/include/placeholders_interface/Placeholders.h +++ b/include/placeholders_interface/Placeholders.h @@ -47,8 +47,6 @@ class Placeholders static void UpdateSyncStatus(const std::wstring &filePath, bool syncState, bool isDirectory); static HRESULT UpdatePinState(const std::wstring &path, const PinState state); static CF_PLACEHOLDER_STATE GetPlaceholderState(const std::wstring &filePath); - static std::vector GetPlaceholderWithStatePending(const std::wstring &filePath); - static bool IsFileValidForSync(const std::wstring &filePath); static PlaceholderResult ConvertToPlaceholder(const std::wstring &fullPath, const std::wstring &serverIdentity); static std::string GetFileIdentity(const std::wstring &filePath); static void UpdateFileIdentity(const std::wstring &filePath, const std::wstring &fileIdentity, bool isDirectory); diff --git a/include/sync_root_interface/callbacks/Callbacks.h b/include/sync_root_interface/callbacks/Callbacks.h index 293bb7aa..10a9b482 100644 --- a/include/sync_root_interface/callbacks/Callbacks.h +++ b/include/sync_root_interface/callbacks/Callbacks.h @@ -4,14 +4,6 @@ void register_threadsafe_callbacks(napi_env env, InputSyncCallbacks input); -// Notify Delete Callback -void register_threadsafe_notify_delete_callback(const std::string &resource_name, napi_env env, InputSyncCallbacks input); -void CALLBACK notify_delete_callback_wrapper(_In_ CONST CF_CALLBACK_INFO *callbackInfo, _In_ CONST CF_CALLBACK_PARAMETERS *callbackParameters); - -// Fetch Placeholders Callback -void register_threadsafe_fetch_placeholders_callback(const std::string &resource_name, napi_env env, InputSyncCallbacks input); -void CALLBACK fetch_placeholders_callback_wrapper(_In_ CONST CF_CALLBACK_INFO *callbackInfo, _In_ CONST CF_CALLBACK_PARAMETERS *callbackParameters); - // Fetch Data Callback void register_threadsafe_fetch_data_callback(const std::string &resource_name, napi_env env, InputSyncCallbacks input); void CALLBACK fetch_data_callback_wrapper(_In_ CONST CF_CALLBACK_INFO *callbackInfo, _In_ CONST CF_CALLBACK_PARAMETERS *callbackParameters); diff --git a/include/sync_root_interface/callbacks/CallbacksContext.h b/include/sync_root_interface/callbacks/CallbacksContext.h index ef40bdd2..ccd8e9ab 100644 --- a/include/sync_root_interface/callbacks/CallbacksContext.h +++ b/include/sync_root_interface/callbacks/CallbacksContext.h @@ -11,15 +11,5 @@ struct InputSyncCallbacks { napi_ref fetch_data_callback_ref; - napi_ref validate_data_callback_ref; napi_ref cancel_fetch_data_callback_ref; - napi_ref fetch_placeholders_callback_ref; - napi_ref cancel_fetch_placeholders_callback_ref; - napi_ref notify_file_open_completion_callback_ref; - napi_ref notify_file_close_completion_callback_ref; - napi_ref notify_dehydrate_callback_ref; - napi_ref notify_dehydrate_completion_callback_ref; - napi_ref notify_delete_callback_ref; - napi_ref notify_delete_completion_callback_ref; - napi_ref none_callback_ref; }; \ No newline at end of file diff --git a/include/virtual_drive/Wrappers.h b/include/virtual_drive/Wrappers.h index 00461098..6538111d 100644 --- a/include/virtual_drive/Wrappers.h +++ b/include/virtual_drive/Wrappers.h @@ -13,7 +13,6 @@ napi_value GetFileIdentityWrapper(napi_env env, napi_callback_info args); napi_value addLoggerPathWrapper(napi_env env, napi_callback_info args); napi_value UpdateSyncStatusWrapper(napi_env env, napi_callback_info args); napi_value GetPlaceholderStateWrapper(napi_env env, napi_callback_info args); -napi_value GetPlaceholderWithStatePendingWrapper(napi_env env, napi_callback_info args); napi_value ConvertToPlaceholderWrapper(napi_env env, napi_callback_info args); napi_value DeleteFileSyncRootWrapper(napi_env env, napi_callback_info args); napi_value UpdateFileIdentityWrapper(napi_env env, napi_callback_info args); diff --git a/native-src/main.cpp b/native-src/main.cpp index 40223357..51b20597 100644 --- a/native-src/main.cpp +++ b/native-src/main.cpp @@ -213,23 +213,6 @@ napi_value init(napi_env env, napi_value exports) return nullptr; } - napi_property_descriptor getPlaceholderWithStatePendingDesc = { - "getPlaceholderWithStatePending", - nullptr, - GetPlaceholderWithStatePendingWrapper, - nullptr, - nullptr, - nullptr, - napi_default, - nullptr}; - - napi_status defineGetPlaceholderWithStatePendingStatus = napi_define_properties(env, exports, 1, &getPlaceholderWithStatePendingDesc); - if (defineGetPlaceholderWithStatePendingStatus != napi_ok) - { - napi_throw_error(env, nullptr, "Failed to define getPlaceholderWithStatePending function"); - return nullptr; - } - napi_property_descriptor convertToPlaceholderDesc = { "convertToPlaceholder", nullptr, diff --git a/native-src/placeholders_interface/Planceholders.cpp b/native-src/placeholders_interface/Planceholders.cpp index d4fd025b..38dd5365 100644 --- a/native-src/placeholders_interface/Planceholders.cpp +++ b/native-src/placeholders_interface/Planceholders.cpp @@ -493,99 +493,6 @@ FileState Placeholders::GetPlaceholderInfo(const std::wstring &directoryPath) return fileState; } -std::vector Placeholders::GetPlaceholderWithStatePending(const std::wstring &directoryPath) -{ - std::vector resultPaths; - - try - { - for (const auto &entry : std::filesystem::directory_iterator(directoryPath, std::filesystem::directory_options::skip_permission_denied)) - { - const auto &path = entry.path().wstring(); - - if (entry.is_directory()) - { - FileState folderState = Placeholders::GetPlaceholderInfo(path); - - if (folderState.syncstate == SyncState::Undefined || folderState.syncstate == SyncState::NotInSync) - { - std::vector subfolderPaths = GetPlaceholderWithStatePending(path); - resultPaths.insert(resultPaths.end(), subfolderPaths.begin(), subfolderPaths.end()); - } - } - else if (entry.is_regular_file()) - { - FileState placeholderState = Placeholders::GetPlaceholderInfo(path); - - bool isFileValidForSync = (placeholderState.syncstate == SyncState::Undefined || placeholderState.syncstate == SyncState::NotInSync); - if (isFileValidForSync && IsFileValidForSync(path)) - { - resultPaths.push_back(path); - } - } - } - } - catch (const std::exception &e) - { - wprintf(L"[GetPlaceholderWithStatePending] Error: %s\n", e.what()); - } - - return resultPaths; -} -bool Placeholders::IsFileValidForSync(const std::wstring &filePath) -{ - // Obtener un handle al archivo - HANDLE fileHandle = CreateFileW( - filePath.c_str(), - FILE_READ_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - nullptr, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - nullptr); - - if (fileHandle == INVALID_HANDLE_VALUE) - { - // No se pudo abrir el archivo - return false; - } - - // Verificar si el archivo está vacío - LARGE_INTEGER fileSize; - if (!GetFileSizeEx(fileHandle, &fileSize)) - { - CloseHandle(fileHandle); - return false; - } - - if (fileSize.QuadPart == 0) - { - CloseHandle(fileHandle); - return false; - } - - LARGE_INTEGER maxFileSize; - maxFileSize.QuadPart = 40LL * 1024 * 1024 * 1024; // 20GB - - if (fileSize.QuadPart > maxFileSize.QuadPart) - { - CloseHandle(fileHandle); - return false; - } - - // // Verificar la extensión del archivo - if (std::filesystem::path(filePath).extension().empty()) - { - CloseHandle(fileHandle); - return false; - } - - // Cerrar el handle del archivo - CloseHandle(fileHandle); - - return true; -} - void Placeholders::ForceShellRefresh(const std::wstring &path) { SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH, path.c_str(), nullptr); diff --git a/native-src/sync_root_interface/SyncRoot.cpp b/native-src/sync_root_interface/SyncRoot.cpp index f0ef8ec3..a72d7512 100644 --- a/native-src/sync_root_interface/SyncRoot.cpp +++ b/native-src/sync_root_interface/SyncRoot.cpp @@ -257,8 +257,6 @@ HRESULT SyncRoot::ConnectSyncRoot(const wchar_t *syncRootPath, InputSyncCallback TransformInputCallbacksToSyncCallbacks(env, syncCallbacks); CF_CALLBACK_REGISTRATION callbackTable[] = { - {CF_CALLBACK_TYPE_NOTIFY_DELETE, notify_delete_callback_wrapper}, - {CF_CALLBACK_TYPE_FETCH_PLACEHOLDERS, fetch_placeholders_callback_wrapper}, {CF_CALLBACK_TYPE_FETCH_DATA, fetch_data_callback_wrapper}, {CF_CALLBACK_TYPE_CANCEL_FETCH_DATA, cancel_fetch_data_callback_wrapper}, CF_CALLBACK_REGISTRATION_END}; diff --git a/native-src/sync_root_interface/callbacks/Callbacks.cpp b/native-src/sync_root_interface/callbacks/Callbacks.cpp index 6858e04d..a2084002 100644 --- a/native-src/sync_root_interface/callbacks/Callbacks.cpp +++ b/native-src/sync_root_interface/callbacks/Callbacks.cpp @@ -3,7 +3,6 @@ void register_threadsafe_callbacks(napi_env env, InputSyncCallbacks input) { - register_threadsafe_notify_delete_callback("NotifyDeleteThreadSafe", env, input); register_threadsafe_fetch_data_callback("FetchDataThreadSafe", env, input); register_threadsafe_cancel_fetch_data_callback("CancelFetchDataThreadSafe", env, input); } \ No newline at end of file diff --git a/native-src/sync_root_interface/callbacks/FetchPlaceholder/FetchPlaceholder.cpp b/native-src/sync_root_interface/callbacks/FetchPlaceholder/FetchPlaceholder.cpp deleted file mode 100644 index 6a205ffa..00000000 --- a/native-src/sync_root_interface/callbacks/FetchPlaceholder/FetchPlaceholder.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -#include - -napi_threadsafe_function g_fetch_placeholder_threadsafe_callback = nullptr; - -inline std::mutex mtx; -inline std::condition_variable cv; -inline bool ready = false; -inline bool callbackResult = false; - -void setup_global_tsfn_fetch_placeholder(napi_threadsafe_function tsfn) -{ - g_fetch_placeholder_threadsafe_callback = tsfn; -} - -void CALLBACK fetch_placeholders_callback_wrapper( - _In_ CONST CF_CALLBACK_INFO *callbackInfo, - _In_ CONST CF_CALLBACK_PARAMETERS *callbackParameters) -{ - wprintf(L"Callback fetch_placeholders_callback_wrapper called\n"); -} \ No newline at end of file diff --git a/native-src/sync_root_interface/callbacks/NotifyDelete/NotifyDeleteCallback.cpp b/native-src/sync_root_interface/callbacks/NotifyDelete/NotifyDeleteCallback.cpp deleted file mode 100644 index f73863fd..00000000 --- a/native-src/sync_root_interface/callbacks/NotifyDelete/NotifyDeleteCallback.cpp +++ /dev/null @@ -1,202 +0,0 @@ -#include -#include -#include -#include -#include - -napi_threadsafe_function g_notify_delete_threadsafe_callback = nullptr; - -inline std::mutex mtx; -inline std::condition_variable cv; -inline bool ready = false; -inline bool callbackResult = false; - -void setup_global_tsfn_delete(napi_threadsafe_function tsfn) -{ - g_notify_delete_threadsafe_callback = tsfn; -} - -struct NotifyDeleteArgs -{ - std::wstring targetPathArg; - std::wstring fileIdentityArg; -}; - -napi_value response_callback_fn_delete(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value argv[1]; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - - if (argc < 1) - { - // Manejar error - return nullptr; - } - - bool response; - napi_get_value_bool(env, argv[0], &response); - - std::lock_guard lock(mtx); - ready = true; - callbackResult = response; - cv.notify_one(); - - return nullptr; -} - -void notify_delete_call(napi_env env, napi_value js_callback, void *context, void *data) -{ - std::wstring *receivedData = static_cast(data); - napi_value js_string; - napi_create_string_utf16(env, reinterpret_cast(receivedData->c_str()), receivedData->size(), &js_string); - - // Crear la función C++ como un valor de N-API para pasar a JS - napi_value js_response_callback_fn; - napi_create_function(env, "responseCallback", NAPI_AUTO_LENGTH, response_callback_fn_delete, nullptr, &js_response_callback_fn); - - napi_value args_to_js_callback[2] = {js_string, js_response_callback_fn}; - - napi_value undefined; - napi_get_undefined(env, &undefined); - napi_value result; - - napi_status status = napi_call_function(env, undefined, js_callback, 2, args_to_js_callback, &result); - if (status != napi_ok) - { - fprintf(stderr, "Failed to call JS function.\n"); - Logger::getInstance().log("Failed to call JS function in notifyDeleteCallback.", LogLevel::ERROR); - return; - } - - cv.notify_one(); - - delete receivedData; -} - -// void notify_delete_call(napi_env env, napi_value js_callback, void* context, void* data) { -// std::wstring* receivedData = static_cast(data); -// napi_value js_string; -// napi_create_string_utf16(env, reinterpret_cast(receivedData->c_str()), receivedData->size(), &js_string); - -// napi_value undefined; -// napi_get_undefined(env, &undefined); -// napi_value result; - -// napi_status status = napi_call_function(env, undefined, js_callback, 1, &js_string, &result); -// if (status != napi_ok) { -// fprintf(stderr, "Failed to call JS function.\n"); -// return; -// } - -// bool js_result = false; // Variable para almacenar el resultado booleano -// status = napi_get_value_bool(env, result, &js_result); // Obtiene el valor booleano desde el objeto napi_value -// if (status != napi_ok) { -// fprintf(stderr, "Failed to convert napi_value to bool.\n"); -// return; -// } - -// { -// std::lock_guard lock(mtx); -// ready = js_result; -// } -// cv.notify_one(); - -// delete receivedData; -// } - -void register_threadsafe_notify_delete_callback(const std::string &resource_name, napi_env env, InputSyncCallbacks input) -{ - std::u16string converted_resource_name = std::u16string(resource_name.begin(), resource_name.end()); - - napi_value resource_name_value; - napi_create_string_utf16(env, converted_resource_name.c_str(), NAPI_AUTO_LENGTH, &resource_name_value); - - napi_threadsafe_function notify_delete_threadsafe_callback; - napi_value notify_delete_callback; - napi_status status_ref = napi_get_reference_value(env, input.notify_delete_callback_ref, ¬ify_delete_callback); - - if (notify_delete_callback == nullptr) - { - fprintf(stderr, "notify_delete_callback is null\n"); - return; - } - - napi_status status = napi_create_threadsafe_function( - env, - notify_delete_callback, - NULL, - resource_name_value, - 0, - 1, - NULL, - NULL, - NULL, - notify_delete_call, - ¬ify_delete_threadsafe_callback); - - if (status != napi_ok) - { - const napi_extended_error_info *errorInfo = NULL; - napi_get_last_error_info(env, &errorInfo); - fprintf(stderr, "Failed to create threadsafe function: %s\n", errorInfo->error_message); - fprintf(stderr, "N-API Status Code: %d\n", errorInfo->error_code); - fprintf(stderr, "Engine-specific error code: %u\n", errorInfo->engine_error_code); - abort(); - } - - setup_global_tsfn_delete(notify_delete_threadsafe_callback); -} - -void CALLBACK notify_delete_callback_wrapper( - _In_ CONST CF_CALLBACK_INFO *callbackInfo, - _In_ CONST CF_CALLBACK_PARAMETERS *callbackParameters) -{ - LPCVOID fileIdentity = callbackInfo->FileIdentity; - DWORD fileIdentityLength = callbackInfo->FileIdentityLength; - - const wchar_t *wchar_ptr = static_cast(fileIdentity); - std::wstring fileIdentityStr(wchar_ptr, fileIdentityLength / sizeof(wchar_t)); - - std::wstring *dataToSend = new std::wstring(fileIdentityStr); - - napi_status status = napi_call_threadsafe_function(g_notify_delete_threadsafe_callback, dataToSend, napi_tsfn_blocking); - - if (status != napi_ok) - { - wprintf(L"Callback called unsuccessfully.\n"); - } - - CF_OPERATION_PARAMETERS opParams = {0}; - - { - std::unique_lock lock(mtx); - while (!ready) - { - cv.wait(lock); - } - } - - opParams.AckDelete.CompletionStatus = callbackResult ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; - opParams.ParamSize = sizeof(CF_OPERATION_PARAMETERS); - - CF_OPERATION_INFO opInfo = {0}; - opInfo.StructSize = sizeof(CF_OPERATION_INFO); - opInfo.Type = CF_OPERATION_TYPE_ACK_DELETE; - opInfo.ConnectionKey = callbackInfo->ConnectionKey; - opInfo.TransferKey = callbackInfo->TransferKey; - - HRESULT hr = CfExecute( - &opInfo, - &opParams); - - { - std::lock_guard lock(mtx); - ready = false; // Reset ready - } - - if (FAILED(hr)) - { - wprintf(L"Error in CfExecute() delete action, HRESULT: %lx\n", hr); - } -} \ No newline at end of file diff --git a/native-src/virtual_drive/Wrappers.cpp b/native-src/virtual_drive/Wrappers.cpp index 2c51689a..02c14488 100644 --- a/native-src/virtual_drive/Wrappers.cpp +++ b/native-src/virtual_drive/Wrappers.cpp @@ -316,23 +316,9 @@ napi_value ConnectSyncRootWrapper(napi_env env, napi_callback_info args) // CALLBACKS InputSyncCallbacks callbacks = {}; - napi_value notifyDeleteCompletionCallback; napi_value fetchDataCallback; napi_value cancelFetchDataCallback; - if (napi_get_named_property(env, argv[1], "notifyDeleteCallback", ¬ifyDeleteCompletionCallback) == napi_ok) - { - napi_create_reference(env, notifyDeleteCompletionCallback, 1, &callbacks.notify_delete_callback_ref); - } - - napi_valuetype valuetype; - napi_status type_status = napi_typeof(env, notifyDeleteCompletionCallback, &valuetype); - if (type_status != napi_ok || valuetype != napi_function) - { - napi_throw_error(env, nullptr, "notifyDeleteCallback should be a function."); - return nullptr; - } - if (napi_get_named_property(env, argv[1], "fetchDataCallback", &fetchDataCallback) == napi_ok) { napi_create_reference(env, fetchDataCallback, 1, &callbacks.fetch_data_callback_ref); @@ -697,39 +683,6 @@ napi_value GetPlaceholderStateWrapper(napi_env env, napi_callback_info args) return result; } -napi_value GetPlaceholderWithStatePendingWrapper(napi_env env, napi_callback_info args) -{ - size_t argc = 1; - napi_value argv[1]; - - napi_get_cb_info(env, args, &argc, argv, nullptr, nullptr); - if (argc < 1) - { - napi_throw_error(env, nullptr, "The path is required for GetPlaceholderWithStatePending"); - return nullptr; - } - - size_t pathLength; - napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength); - - std::unique_ptr widePath(new char16_t[pathLength + 1]); - - napi_get_value_string_utf16(env, argv[0], widePath.get(), pathLength + 1, nullptr); - - std::vector state = Placeholders::GetPlaceholderWithStatePending(reinterpret_cast(widePath.get())); - - napi_value result; - napi_create_array_with_length(env, state.size(), &result); - for (size_t i = 0; i < state.size(); ++i) - { - napi_value jsString; - napi_create_string_utf16(env, reinterpret_cast(state[i].c_str()), state[i].length(), &jsString); - napi_set_element(env, result, i, jsString); - } - - return result; -} - napi_value ConvertToPlaceholderWrapper(napi_env env, napi_callback_info args) { size_t argc = 2; diff --git a/package.json b/package.json index ec713fb0..52976d4e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@internxt/node-win", - "version": "1.0.19", + "version": "1.0.20", "description": "Drive desktop node addon", "main": "dist/index.js", "types": "dist/index.d.ts",