@@ -3056,42 +3056,6 @@ static void GetFormatOfExtensionlessFile(
30563056 return args.GetReturnValue ().Set (EXTENSIONLESS_FORMAT_JAVASCRIPT);
30573057}
30583058
3059- #ifdef _WIN32
3060- #define BufferValueToPath (str ) \
3061- std::filesystem::path (ConvertToWideString(str.ToString(), CP_UTF8))
3062-
3063- std::string ConvertWideToUTF8(const std::wstring& wstr) {
3064- if (wstr.empty ()) return std::string ();
3065-
3066- int size_needed = WideCharToMultiByte (CP_UTF8,
3067- 0 ,
3068- &wstr[0 ],
3069- static_cast <int >(wstr.size ()),
3070- nullptr ,
3071- 0 ,
3072- nullptr ,
3073- nullptr );
3074- std::string strTo (size_needed, 0 );
3075- WideCharToMultiByte (CP_UTF8,
3076- 0 ,
3077- &wstr[0 ],
3078- static_cast <int >(wstr.size ()),
3079- &strTo[0 ],
3080- size_needed,
3081- nullptr ,
3082- nullptr );
3083- return strTo;
3084- }
3085-
3086- #define PathToString (path ) ConvertWideToUTF8(path.wstring());
3087-
3088- #else // _WIN32
3089-
3090- #define BufferValueToPath (str ) std::filesystem::path(str.ToStringView());
3091- #define PathToString (path ) path.native();
3092-
3093- #endif // _WIN32
3094-
30953059static void CpSyncCheckPaths (const FunctionCallbackInfo<Value>& args) {
30963060 Environment* env = Environment::GetCurrent (args);
30973061 Isolate* isolate = env->isolate ();
@@ -3104,15 +3068,15 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
31043068 THROW_IF_INSUFFICIENT_PERMISSIONS (
31053069 env, permission::PermissionScope::kFileSystemRead , src.ToStringView ());
31063070
3107- auto src_path = BufferValueToPath ( src);
3071+ auto src_path = src. ToPath ( );
31083072
31093073 BufferValue dest (isolate, args[1 ]);
31103074 CHECK_NOT_NULL (*dest);
31113075 ToNamespacedPath (env, &dest);
31123076 THROW_IF_INSUFFICIENT_PERMISSIONS (
31133077 env, permission::PermissionScope::kFileSystemWrite , dest.ToStringView ());
31143078
3115- auto dest_path = BufferValueToPath ( dest);
3079+ auto dest_path = dest. ToPath ( );
31163080 bool dereference = args[2 ]->IsTrue ();
31173081 bool recursive = args[3 ]->IsTrue ();
31183082
@@ -3141,8 +3105,8 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
31413105 (src_status.type () == std::filesystem::file_type::directory) ||
31423106 (dereference && src_status.type () == std::filesystem::file_type::symlink);
31433107
3144- auto src_path_str = PathToString (src_path);
3145- auto dest_path_str = PathToString (dest_path);
3108+ auto src_path_str = ConvertPathToUTF8 (src_path);
3109+ auto dest_path_str = ConvertPathToUTF8 (dest_path);
31463110
31473111 if (!error_code) {
31483112 // Check if src and dest are identical.
@@ -3237,7 +3201,7 @@ static bool CopyUtimes(const std::filesystem::path& src,
32373201 uv_fs_t req;
32383202 auto cleanup = OnScopeLeave ([&req]() { uv_fs_req_cleanup (&req); });
32393203
3240- auto src_path_str = PathToString (src);
3204+ auto src_path_str = ConvertPathToUTF8 (src);
32413205 int result = uv_fs_stat (nullptr , &req, src_path_str.c_str (), nullptr );
32423206 if (is_uv_error (result)) {
32433207 env->ThrowUVException (result, " stat" , nullptr , src_path_str.c_str ());
@@ -3248,7 +3212,7 @@ static bool CopyUtimes(const std::filesystem::path& src,
32483212 const double source_atime = s->st_atim .tv_sec + s->st_atim .tv_nsec / 1e9 ;
32493213 const double source_mtime = s->st_mtim .tv_sec + s->st_mtim .tv_nsec / 1e9 ;
32503214
3251- auto dest_file_path_str = PathToString (dest);
3215+ auto dest_file_path_str = ConvertPathToUTF8 (dest);
32523216 int utime_result = uv_fs_utime (nullptr ,
32533217 &req,
32543218 dest_file_path_str.c_str (),
@@ -3383,7 +3347,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
33833347 std::error_code error;
33843348 for (auto dir_entry : std::filesystem::directory_iterator (src)) {
33853349 auto dest_file_path = dest / dir_entry.path ().filename ();
3386- auto dest_str = PathToString (dest);
3350+ auto dest_str = ConvertPathToUTF8 (dest);
33873351
33883352 if (dir_entry.is_symlink ()) {
33893353 if (verbatim_symlinks) {
@@ -3446,7 +3410,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
34463410 }
34473411 } else if (std::filesystem::is_regular_file (dest_file_path)) {
34483412 if (!dereference || (!force && error_on_exist)) {
3449- auto dest_file_path_str = PathToString (dest_file_path);
3413+ auto dest_file_path_str = ConvertPathToUTF8 (dest_file_path);
34503414 env->ThrowStdErrException (
34513415 std::make_error_code (std::errc::file_exists),
34523416 " cp" ,
0 commit comments