@@ -3175,42 +3175,6 @@ static void GetFormatOfExtensionlessFile(
31753175 return args.GetReturnValue ().Set (EXTENSIONLESS_FORMAT_JAVASCRIPT);
31763176}
31773177
3178- #ifdef _WIN32
3179- #define BufferValueToPath (str ) \
3180- std::filesystem::path (ConvertToWideString(str.ToString(), CP_UTF8))
3181-
3182- std::string ConvertWideToUTF8(const std::wstring& wstr) {
3183- if (wstr.empty ()) return std::string ();
3184-
3185- int size_needed = WideCharToMultiByte (CP_UTF8,
3186- 0 ,
3187- &wstr[0 ],
3188- static_cast <int >(wstr.size ()),
3189- nullptr ,
3190- 0 ,
3191- nullptr ,
3192- nullptr );
3193- std::string strTo (size_needed, 0 );
3194- WideCharToMultiByte (CP_UTF8,
3195- 0 ,
3196- &wstr[0 ],
3197- static_cast <int >(wstr.size ()),
3198- &strTo[0 ],
3199- size_needed,
3200- nullptr ,
3201- nullptr );
3202- return strTo;
3203- }
3204-
3205- #define PathToString (path ) ConvertWideToUTF8(path.wstring());
3206-
3207- #else // _WIN32
3208-
3209- #define BufferValueToPath (str ) std::filesystem::path(str.ToStringView());
3210- #define PathToString (path ) path.native();
3211-
3212- #endif // _WIN32
3213-
32143178static void CpSyncCheckPaths (const FunctionCallbackInfo<Value>& args) {
32153179 Environment* env = Environment::GetCurrent (args);
32163180 Isolate* isolate = env->isolate ();
@@ -3223,15 +3187,15 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
32233187 THROW_IF_INSUFFICIENT_PERMISSIONS (
32243188 env, permission::PermissionScope::kFileSystemRead , src.ToStringView ());
32253189
3226- auto src_path = BufferValueToPath ( src);
3190+ auto src_path = src. ToPath ( );
32273191
32283192 BufferValue dest (isolate, args[1 ]);
32293193 CHECK_NOT_NULL (*dest);
32303194 ToNamespacedPath (env, &dest);
32313195 THROW_IF_INSUFFICIENT_PERMISSIONS (
32323196 env, permission::PermissionScope::kFileSystemWrite , dest.ToStringView ());
32333197
3234- auto dest_path = BufferValueToPath ( dest);
3198+ auto dest_path = dest. ToPath ( );
32353199 bool dereference = args[2 ]->IsTrue ();
32363200 bool recursive = args[3 ]->IsTrue ();
32373201
@@ -3260,8 +3224,8 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
32603224 (src_status.type () == std::filesystem::file_type::directory) ||
32613225 (dereference && src_status.type () == std::filesystem::file_type::symlink);
32623226
3263- auto src_path_str = PathToString (src_path);
3264- auto dest_path_str = PathToString (dest_path);
3227+ auto src_path_str = ConvertPathToUTF8 (src_path);
3228+ auto dest_path_str = ConvertPathToUTF8 (dest_path);
32653229
32663230 if (!error_code) {
32673231 // Check if src and dest are identical.
@@ -3356,7 +3320,7 @@ static bool CopyUtimes(const std::filesystem::path& src,
33563320 uv_fs_t req;
33573321 auto cleanup = OnScopeLeave ([&req]() { uv_fs_req_cleanup (&req); });
33583322
3359- auto src_path_str = PathToString (src);
3323+ auto src_path_str = ConvertPathToUTF8 (src);
33603324 int result = uv_fs_stat (nullptr , &req, src_path_str.c_str (), nullptr );
33613325 if (is_uv_error (result)) {
33623326 env->ThrowUVException (result, " stat" , nullptr , src_path_str.c_str ());
@@ -3367,7 +3331,7 @@ static bool CopyUtimes(const std::filesystem::path& src,
33673331 const double source_atime = s->st_atim .tv_sec + s->st_atim .tv_nsec / 1e9 ;
33683332 const double source_mtime = s->st_mtim .tv_sec + s->st_mtim .tv_nsec / 1e9 ;
33693333
3370- auto dest_file_path_str = PathToString (dest);
3334+ auto dest_file_path_str = ConvertPathToUTF8 (dest);
33713335 int utime_result = uv_fs_utime (nullptr ,
33723336 &req,
33733337 dest_file_path_str.c_str (),
@@ -3502,7 +3466,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
35023466 std::error_code error;
35033467 for (auto dir_entry : std::filesystem::directory_iterator (src)) {
35043468 auto dest_file_path = dest / dir_entry.path ().filename ();
3505- auto dest_str = PathToString (dest);
3469+ auto dest_str = ConvertPathToUTF8 (dest);
35063470
35073471 if (dir_entry.is_symlink ()) {
35083472 if (verbatim_symlinks) {
@@ -3561,7 +3525,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
35613525 }
35623526 } else if (std::filesystem::is_regular_file (dest_file_path)) {
35633527 if (!dereference || (!force && error_on_exist)) {
3564- auto dest_file_path_str = PathToString (dest_file_path);
3528+ auto dest_file_path_str = ConvertPathToUTF8 (dest_file_path);
35653529 env->ThrowStdErrException (
35663530 std::make_error_code (std::errc::file_exists),
35673531 " cp" ,
0 commit comments