@@ -3169,19 +3169,6 @@ static void GetFormatOfExtensionlessFile(
31693169 return args.GetReturnValue ().Set (EXTENSIONLESS_FORMAT_JAVASCRIPT);
31703170}
31713171
3172- #ifdef _WIN32
3173- #define BufferValueToPath (str ) \
3174- std::filesystem::path (ConvertToWideString(str.ToString(), CP_UTF8))
3175-
3176- #define PathToString (path ) ConvertWideToUTF8(path.wstring());
3177-
3178- #else // _WIN32
3179-
3180- #define BufferValueToPath (str ) std::filesystem::path(str.ToStringView());
3181- #define PathToString (path ) path.native();
3182-
3183- #endif // _WIN32
3184-
31853172static void CpSyncCheckPaths (const FunctionCallbackInfo<Value>& args) {
31863173 Environment* env = Environment::GetCurrent (args);
31873174 Isolate* isolate = env->isolate ();
@@ -3194,15 +3181,15 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
31943181 THROW_IF_INSUFFICIENT_PERMISSIONS (
31953182 env, permission::PermissionScope::kFileSystemRead , src.ToStringView ());
31963183
3197- auto src_path = BufferValueToPath ( src);
3184+ auto src_path = src. ToPath ( );
31983185
31993186 BufferValue dest (isolate, args[1 ]);
32003187 CHECK_NOT_NULL (*dest);
32013188 ToNamespacedPath (env, &dest);
32023189 THROW_IF_INSUFFICIENT_PERMISSIONS (
32033190 env, permission::PermissionScope::kFileSystemWrite , dest.ToStringView ());
32043191
3205- auto dest_path = BufferValueToPath ( dest);
3192+ auto dest_path = dest. ToPath ( );
32063193 bool dereference = args[2 ]->IsTrue ();
32073194 bool recursive = args[3 ]->IsTrue ();
32083195
@@ -3231,8 +3218,8 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
32313218 (src_status.type () == std::filesystem::file_type::directory) ||
32323219 (dereference && src_status.type () == std::filesystem::file_type::symlink);
32333220
3234- auto src_path_str = PathToString (src_path);
3235- auto dest_path_str = PathToString (dest_path);
3221+ auto src_path_str = ConvertPathToUTF8 (src_path);
3222+ auto dest_path_str = ConvertPathToUTF8 (dest_path);
32363223
32373224 if (!error_code) {
32383225 // Check if src and dest are identical.
@@ -3327,7 +3314,7 @@ static bool CopyUtimes(const std::filesystem::path& src,
33273314 uv_fs_t req;
33283315 auto cleanup = OnScopeLeave ([&req]() { uv_fs_req_cleanup (&req); });
33293316
3330- auto src_path_str = PathToString (src);
3317+ auto src_path_str = ConvertPathToUTF8 (src);
33313318 int result = uv_fs_stat (nullptr , &req, src_path_str.c_str (), nullptr );
33323319 if (is_uv_error (result)) {
33333320 env->ThrowUVException (result, " stat" , nullptr , src_path_str.c_str ());
@@ -3338,7 +3325,7 @@ static bool CopyUtimes(const std::filesystem::path& src,
33383325 const double source_atime = s->st_atim .tv_sec + s->st_atim .tv_nsec / 1e9 ;
33393326 const double source_mtime = s->st_mtim .tv_sec + s->st_mtim .tv_nsec / 1e9 ;
33403327
3341- auto dest_file_path_str = PathToString (dest);
3328+ auto dest_file_path_str = ConvertPathToUTF8 (dest);
33423329 int utime_result = uv_fs_utime (nullptr ,
33433330 &req,
33443331 dest_file_path_str.c_str (),
@@ -3473,7 +3460,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
34733460 std::error_code error;
34743461 for (auto dir_entry : std::filesystem::directory_iterator (src)) {
34753462 auto dest_file_path = dest / dir_entry.path ().filename ();
3476- auto dest_str = PathToString (dest);
3463+ auto dest_str = ConvertPathToUTF8 (dest);
34773464
34783465 if (dir_entry.is_symlink ()) {
34793466 if (verbatim_symlinks) {
@@ -3536,7 +3523,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
35363523 }
35373524 } else if (std::filesystem::is_regular_file (dest_file_path)) {
35383525 if (!dereference || (!force && error_on_exist)) {
3539- auto dest_file_path_str = PathToString (dest_file_path);
3526+ auto dest_file_path_str = ConvertPathToUTF8 (dest_file_path);
35403527 env->ThrowStdErrException (
35413528 std::make_error_code (std::errc::file_exists),
35423529 " cp" ,
0 commit comments