Skip to content

Commit f626ddb

Browse files
Simplify fetch data (#200)
* Create napi safe wrap * Extract create folder placeholder * Extract create file placeholder * Extract get file identity * Update package.json * Extract connect sync root * Extract hydrate file * Hydrate file thread safe * Improve safe wrap * Remove delete file from c++ * Extract convert to placeholder * Refactor register sync root * Extract code * Improve * Simplify providerId * Commit * Commit * Commit * Update get_registered_sync_roots.cpp * Update addon.node * Commt * Commit * Simplify unregister * Fix wrapper * Remove context * Improve napi * Template napi_extract_args * Extract dehydrate file wrapper * Refactor dehydrate file * Throw exceptions * Commit * Extract disconnect sync root * Extract get placeholder state * Remove sync state * Extract update sync status * Update publish-npm.yml * Update addon.node * Clean * Refactor cancel fetch data * Update CancelFetchDataCallback.cpp * Update addon.node * Simplify fetch data * Remove AddFolderToSearchIndexer * Update node * Update FetchData.cpp * Update addon.node * Update sonar-analysis.yml * Fix pipelines * Update package.json
1 parent 4b2e121 commit f626ddb

8 files changed

Lines changed: 21 additions & 86 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish package to npmjs
1+
name: Publish
22

33
on:
44
release:

.github/workflows/sonar-analysis.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Pull request checks
1+
name: Sonar analysis
22

33
on:
44
pull_request:
@@ -9,8 +9,8 @@ on:
99

1010
jobs:
1111
sonar_analysis:
12-
runs-on: windows-latest
13-
timeout-minutes: 15
12+
runs-on: windows-2022
13+
timeout-minutes: 10
1414

1515
env:
1616
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
@@ -26,12 +26,6 @@ jobs:
2626
with:
2727
node-version: 20
2828

29-
- name: Install Windows SDK 10.0.22621.0
30-
uses: ChristopheLav/windows-sdk-install@88d72875fb873886ea398ed04041446da6f26f86 # v1.0.3
31-
with:
32-
version-sdk: 22621
33-
features: "OptionId.DesktopCPPx86,OptionId.DesktopCPPx64"
34-
3529
- name: Install node-gyp
3630
run: npm install -g node-gyp
3731

.github/workflows/stale-prs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Mark stale PRs
1+
name: Stale PRs
22

33
on:
44
schedule:

dist/addon.node

-1 KB
Binary file not shown.

native-src/sync_root_interface/callbacks/CancelFetchData/CancelFetchDataCallback.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ struct CancelFetchDataArgs {
2323
: fileIdentityArg(fileId), context(ctx) {}
2424
};
2525

26-
void setup_global_tsfn_cancel_fetch_data(napi_threadsafe_function tsfn)
27-
{
28-
g_cancel_fetch_data_threadsafe_callback = tsfn;
29-
}
30-
3126
void notify_cancel_fetch_data_call(napi_env env, napi_value js_callback, void *context, void *data)
3227
{
3328
CancelFetchDataArgs *args = static_cast<CancelFetchDataArgs *>(data);
@@ -89,7 +84,7 @@ void register_threadsafe_cancel_fetch_data_callback(const std::string &resource_
8984
return;
9085
}
9186

92-
setup_global_tsfn_cancel_fetch_data(tsfn_cancel_fetch_data);
87+
g_cancel_fetch_data_threadsafe_callback = tsfn_cancel_fetch_data;
9388
}
9489

9590
void CALLBACK cancel_fetch_data_callback_wrapper(

native-src/sync_root_interface/callbacks/FetchData/FetchData.cpp

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@
2121

2222
napi_threadsafe_function g_fetch_data_threadsafe_callback = nullptr;
2323

24-
inline std::mutex mtx;
25-
inline std::mutex mtx_download;
26-
inline std::condition_variable cv;
27-
inline std::condition_variable cv_download;
28-
inline bool ready_download = false;
29-
inline bool callbackResult = false;
30-
3124
#define FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
3225

3326
#define CF_SIZE_OF_OP_PARAM(field) \
@@ -38,18 +31,6 @@ inline bool callbackResult = false;
3831

3932
#define CHUNKDELAYMS 250
4033

41-
std::wstring g_full_client_path;
42-
43-
struct FetchDataArgs
44-
{
45-
std::wstring fileIdentityArg;
46-
};
47-
48-
void load_data()
49-
{
50-
printf("load_data called");
51-
}
52-
5334
napi_value create_response(napi_env env, bool finished, float progress)
5435
{
5536
napi_value result_object;
@@ -72,25 +53,6 @@ napi_value create_response(napi_env env, bool finished, float progress)
7253
return promise;
7354
}
7455

75-
std::string WStringToString(const std::wstring &wstr)
76-
{
77-
try
78-
{
79-
if (wstr.empty())
80-
return std::string();
81-
82-
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
83-
std::string utf8_str = converter.to_bytes(wstr);
84-
85-
return utf8_str;
86-
}
87-
catch (const std::exception &e)
88-
{
89-
Logger::getInstance().log("Error converting wstring to string: " + std::string(e.what()), LogLevel::ERROR);
90-
return "";
91-
}
92-
}
93-
9456
static size_t file_incremental_reading(napi_env env,
9557
TransferContext &ctx,
9658
bool final_step,
@@ -342,20 +304,14 @@ static void notify_fetch_data_call(napi_env env, napi_value js_callback, void *c
342304

343305
void register_threadsafe_fetch_data_callback(const std::string &resource_name, napi_env env, InputSyncCallbacks input)
344306
{
345-
Logger::getInstance().log("register_threadsafe_fetch_data_callback called", LogLevel::DEBUG);
346-
std::u16string converted_resource_name = std::u16string(resource_name.begin(), resource_name.end());
307+
std::u16string converted_resource_name(resource_name.begin(), resource_name.end());
347308

348309
napi_value resource_name_value;
349-
napi_create_string_utf16(env,
350-
converted_resource_name.c_str(),
351-
NAPI_AUTO_LENGTH,
352-
&resource_name_value);
310+
napi_create_string_utf16(env, converted_resource_name.c_str(), NAPI_AUTO_LENGTH, &resource_name_value);
353311

354312
napi_threadsafe_function tsfn_fetch_data;
355313
napi_value fetch_data_value;
356-
napi_status status_ref = napi_get_reference_value(env, input.fetch_data_callback_ref, &fetch_data_value);
357-
358-
Logger::getInstance().log("status_ref: " + std::to_string(status_ref), LogLevel::DEBUG);
314+
napi_get_reference_value(env, input.fetch_data_callback_ref, &fetch_data_value);
359315

360316
napi_status status = napi_create_threadsafe_function(
361317
env,
@@ -370,8 +326,9 @@ void register_threadsafe_fetch_data_callback(const std::string &resource_name, n
370326
notify_fetch_data_call,
371327
&tsfn_fetch_data);
372328

373-
if (status != napi_ok) {
374-
Logger::getInstance().log("Failed to create threadsafe function (fetch_data).", LogLevel::ERROR);
329+
if (status != napi_ok)
330+
{
331+
napi_throw_error(env, nullptr, "Failed to create fetch data threadsafe function");
375332
return;
376333
}
377334

@@ -392,9 +349,10 @@ void CALLBACK fetch_data_callback_wrapper(
392349
ctx->requiredLength = callbackParameters->FetchData.RequiredLength;
393350
ctx->requiredOffset = callbackParameters->FetchData.RequiredFileOffset;
394351
ctx->callbackInfo = *callbackInfo;
395-
std::wstring fullClientPath(callbackInfo->VolumeDosName);
396-
fullClientPath.append(callbackInfo->NormalizedPath);
397-
ctx->fullClientPath = fullClientPath;
352+
353+
std::wstring fullClientPath(callbackInfo->VolumeDosName); // e.g., "C:"
354+
fullClientPath.append(callbackInfo->NormalizedPath); // e.g., "\Users\file.txt"
355+
ctx->fullClientPath = fullClientPath; // Result: "C:\Users\file.txt"
398356

399357
Logger::getInstance().log("Full download path: "
400358
+ Logger::fromWStringToString(fullClientPath),
@@ -406,13 +364,7 @@ void CALLBACK fetch_data_callback_wrapper(
406364
return;
407365
}
408366

409-
napi_status status = napi_call_threadsafe_function(
410-
g_fetch_data_threadsafe_callback,
411-
ctx.get(),
412-
napi_tsfn_blocking);
413-
if (status != napi_ok) {
414-
Logger::getInstance().log("Callback called unsuccessfully in fetch_data_callback_wrapper.", LogLevel::ERROR);
415-
}
367+
napi_call_threadsafe_function(g_fetch_data_threadsafe_callback, ctx.get(), napi_tsfn_blocking);
416368

417369
Logger::getInstance().log("fetch_data_callback_wrapper after napi_call_threadsafe_function", LogLevel::DEBUG);
418370

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
#include "TransferContext.h"
22

33
struct CfTransferKeyLess {
4-
bool operator()(const CF_TRANSFER_KEY &a, const CF_TRANSFER_KEY &b) const
5-
{
4+
bool operator()(const CF_TRANSFER_KEY &a, const CF_TRANSFER_KEY &b) const {
65
return a.QuadPart < b.QuadPart;
76
}
87
};
98

109
static std::map<CF_TRANSFER_KEY, std::shared_ptr<TransferContext>, CfTransferKeyLess> g_transferContextMap;
1110

12-
1311
static std::mutex g_contextMapMutex;
1412

15-
std::shared_ptr<TransferContext> GetOrCreateTransferContext(
16-
CF_CONNECTION_KEY connKey,
17-
CF_TRANSFER_KEY transferKey)
18-
{
13+
std::shared_ptr<TransferContext> GetOrCreateTransferContext(CF_CONNECTION_KEY connKey, CF_TRANSFER_KEY transferKey) {
1914
std::lock_guard<std::mutex> lock(g_contextMapMutex);
2015

2116
auto it = g_transferContextMap.find(transferKey);
@@ -30,8 +25,7 @@ std::shared_ptr<TransferContext> GetOrCreateTransferContext(
3025
return ctx;
3126
}
3227

33-
void RemoveTransferContext(CF_TRANSFER_KEY transferKey)
34-
{
28+
void RemoveTransferContext(CF_TRANSFER_KEY transferKey) {
3529
std::lock_guard<std::mutex> lock(g_contextMapMutex);
3630
g_transferContextMap.erase(transferKey);
3731
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@internxt/node-win",
3-
"version": "1.0.24",
3+
"version": "1.0.25",
44
"author": "Internxt <hello@internxt.com>",
55
"description": "Drive desktop node addon",
66
"main": "dist/index.js",

0 commit comments

Comments
 (0)