@@ -3184,42 +3184,6 @@ static void GetFormatOfExtensionlessFile(
31843184 return args.GetReturnValue ().Set (EXTENSIONLESS_FORMAT_JAVASCRIPT);
31853185}
31863186
3187- #ifdef _WIN32
3188- #define BufferValueToPath (str ) \
3189- std::filesystem::path (ConvertToWideString(str.ToString(), CP_UTF8))
3190-
3191- std::string ConvertWideToUTF8(const std::wstring& wstr) {
3192- if (wstr.empty ()) return std::string ();
3193-
3194- int size_needed = WideCharToMultiByte (CP_UTF8,
3195- 0 ,
3196- &wstr[0 ],
3197- static_cast <int >(wstr.size ()),
3198- nullptr ,
3199- 0 ,
3200- nullptr ,
3201- nullptr );
3202- std::string strTo (size_needed, 0 );
3203- WideCharToMultiByte (CP_UTF8,
3204- 0 ,
3205- &wstr[0 ],
3206- static_cast <int >(wstr.size ()),
3207- &strTo[0 ],
3208- size_needed,
3209- nullptr ,
3210- nullptr );
3211- return strTo;
3212- }
3213-
3214- #define PathToString (path ) ConvertWideToUTF8(path.wstring());
3215-
3216- #else // _WIN32
3217-
3218- #define BufferValueToPath (str ) std::filesystem::path(str.ToStringView());
3219- #define PathToString (path ) path.native();
3220-
3221- #endif // _WIN32
3222-
32233187static void CpSyncCheckPaths (const FunctionCallbackInfo<Value>& args) {
32243188 Environment* env = Environment::GetCurrent (args);
32253189 Isolate* isolate = env->isolate ();
@@ -3232,15 +3196,15 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
32323196 THROW_IF_INSUFFICIENT_PERMISSIONS (
32333197 env, permission::PermissionScope::kFileSystemRead , src.ToStringView ());
32343198
3235- auto src_path = BufferValueToPath ( src);
3199+ auto src_path = src. ToPath ( );
32363200
32373201 BufferValue dest (isolate, args[1 ]);
32383202 CHECK_NOT_NULL (*dest);
32393203 ToNamespacedPath (env, &dest);
32403204 THROW_IF_INSUFFICIENT_PERMISSIONS (
32413205 env, permission::PermissionScope::kFileSystemWrite , dest.ToStringView ());
32423206
3243- auto dest_path = BufferValueToPath ( dest);
3207+ auto dest_path = dest. ToPath ( );
32443208 bool dereference = args[2 ]->IsTrue ();
32453209 bool recursive = args[3 ]->IsTrue ();
32463210
@@ -3269,8 +3233,8 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
32693233 (src_status.type () == std::filesystem::file_type::directory) ||
32703234 (dereference && src_status.type () == std::filesystem::file_type::symlink);
32713235
3272- auto src_path_str = PathToString (src_path);
3273- auto dest_path_str = PathToString (dest_path);
3236+ auto src_path_str = ConvertPathToUTF8 (src_path);
3237+ auto dest_path_str = ConvertPathToUTF8 (dest_path);
32743238
32753239 if (!error_code) {
32763240 // Check if src and dest are identical.
@@ -3365,7 +3329,7 @@ static bool CopyUtimes(const std::filesystem::path& src,
33653329 uv_fs_t req;
33663330 auto cleanup = OnScopeLeave ([&req]() { uv_fs_req_cleanup (&req); });
33673331
3368- auto src_path_str = PathToString (src);
3332+ auto src_path_str = ConvertPathToUTF8 (src);
33693333 int result = uv_fs_stat (nullptr , &req, src_path_str.c_str (), nullptr );
33703334 if (is_uv_error (result)) {
33713335 env->ThrowUVException (result, " stat" , nullptr , src_path_str.c_str ());
@@ -3376,7 +3340,7 @@ static bool CopyUtimes(const std::filesystem::path& src,
33763340 const double source_atime = s->st_atim .tv_sec + s->st_atim .tv_nsec / 1e9 ;
33773341 const double source_mtime = s->st_mtim .tv_sec + s->st_mtim .tv_nsec / 1e9 ;
33783342
3379- auto dest_file_path_str = PathToString (dest);
3343+ auto dest_file_path_str = ConvertPathToUTF8 (dest);
33803344 int utime_result = uv_fs_utime (nullptr ,
33813345 &req,
33823346 dest_file_path_str.c_str (),
@@ -3511,7 +3475,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
35113475 std::error_code error;
35123476 for (auto dir_entry : std::filesystem::directory_iterator (src)) {
35133477 auto dest_file_path = dest / dir_entry.path ().filename ();
3514- auto dest_str = PathToString (dest);
3478+ auto dest_str = ConvertPathToUTF8 (dest);
35153479
35163480 if (dir_entry.is_symlink ()) {
35173481 if (verbatim_symlinks) {
@@ -3570,7 +3534,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
35703534 }
35713535 } else if (std::filesystem::is_regular_file (dest_file_path)) {
35723536 if (!dereference || (!force && error_on_exist)) {
3573- auto dest_file_path_str = PathToString (dest_file_path);
3537+ auto dest_file_path_str = ConvertPathToUTF8 (dest_file_path);
35743538 env->ThrowStdErrException (
35753539 std::make_error_code (std::errc::file_exists),
35763540 " cp" ,
0 commit comments