Hydrate file thread safe#188
Conversation
| static std::string GetFileIdentity(const wchar_t *path); | ||
| static void HydrateFile(const wchar_t *filePath); | ||
| static void DehydrateFile(const wchar_t *filePath); | ||
| static void DeleteFileSyncRoot(const wchar_t *path); |
There was a problem hiding this comment.
This is not used in javascript so we can remove it.
| } | ||
|
|
||
| #define NAPI_SAFE_WRAP(env, info, fn) \ | ||
| napi_safe_wrap(env, info, fn, __FUNCTION__) |
There was a problem hiding this comment.
Basically we have created this wrapper so we log also the name of the function that is wrapping. Why? This is wrapper that wraps all unexpected C++ exceptions and converts them in a javascript exception (napi_throw_error). We concatenate the message with the name of the function FUNCTION.
|
|
||
| if (SUCCEEDED(hr)) { | ||
| connectionMap[syncRootPath] = *connectionKey; | ||
| } |
There was a problem hiding this comment.
Here we have removed the try catch since we already obtaining this using the previous NAPI_SAFE_WRAP in Wrappers.cpp
| size_t pathLength; | ||
| napi_get_value_string_utf16(env, argv[0], nullptr, 0, &pathLength); | ||
| syncRootPath = new WCHAR[pathLength + 1]; | ||
| napi_get_value_string_utf16(env, argv[0], reinterpret_cast<char16_t *>(const_cast<wchar_t *>(syncRootPath)), pathLength + 1, nullptr); |
There was a problem hiding this comment.
This could lead to a memory leak.
| { | ||
| napi_throw_error(env, nullptr, "cancelFetchDataCallback should be a function."); | ||
| return nullptr; | ||
| } |
There was a problem hiding this comment.
Since we control the input from javascript we don't need to validate here that we pass functions, otherwise it will break in development and we make this function clearer and simpler.
| napi_create_promise(env, &deferred, &promise); | ||
|
|
||
| // Lanzar la operación asíncrona en un hilo separado | ||
| std::thread([deferred, fullPath, env]() |
There was a problem hiding this comment.
This was leading to a crash in the sync process when we were hydrating a file already hydrated. Why? This is a native thread of C++, not one from the napi (javascript). Now we create an async work using napi.
There was a problem hiding this comment.
The try catchs have been encapsulated into execute_work function and complete_work.
No description provided.