@@ -1677,33 +1677,33 @@ static void RmSync(const FunctionCallbackInfo<Value>& args) {
16771677 maxRetries--;
16781678 }
16791679
1680- // This is required since std::filesystem::path::c_str() returns different
1681- // values in Windows and Unix.
1680+ // On Windows path::c_str() returns wide char, convert to std::string first.
1681+ std::string file_path_str = file_path.string ();
1682+ const char * path_c_str = file_path_str.c_str ();
16821683#ifdef _WIN32
1683- auto file_ = file_path.string ().c_str ();
16841684 int permission_denied_error = EPERM;
16851685#else
1686- auto file_ = file_path.c_str ();
16871686 int permission_denied_error = EACCES;
16881687#endif // !_WIN32
16891688
16901689 if (error == std::errc::operation_not_permitted) {
1691- std::string message = " Operation not permitted: " + file_path. string () ;
1692- return env->ThrowErrnoException (EPERM, " rm" , message.c_str (), file_ );
1690+ std::string message = " Operation not permitted: " + file_path_str ;
1691+ return env->ThrowErrnoException (EPERM, " rm" , message.c_str (), path_c_str );
16931692 } else if (error == std::errc::directory_not_empty) {
1694- std::string message = " Directory not empty: " + file_path. string () ;
1695- return env->ThrowErrnoException (EACCES, " rm" , message.c_str (), file_ );
1693+ std::string message = " Directory not empty: " + file_path_str ;
1694+ return env->ThrowErrnoException (EACCES, " rm" , message.c_str (), path_c_str );
16961695 } else if (error == std::errc::not_a_directory) {
1697- std::string message = " Not a directory: " + file_path. string () ;
1698- return env->ThrowErrnoException (ENOTDIR, " rm" , message.c_str (), file_ );
1696+ std::string message = " Not a directory: " + file_path_str ;
1697+ return env->ThrowErrnoException (ENOTDIR, " rm" , message.c_str (), path_c_str );
16991698 } else if (error == std::errc::permission_denied) {
1700- std::string message = " Permission denied: " + file_path. string () ;
1699+ std::string message = " Permission denied: " + file_path_str ;
17011700 return env->ThrowErrnoException (
1702- permission_denied_error, " rm" , message.c_str (), file_ );
1701+ permission_denied_error, " rm" , message.c_str (), path_c_str );
17031702 }
17041703
17051704 std::string message = " Unknown error: " + error.message ();
1706- return env->ThrowErrnoException (UV_UNKNOWN, " rm" , message.c_str (), file_);
1705+ return env->ThrowErrnoException (
1706+ UV_UNKNOWN, " rm" , message.c_str (), path_c_str);
17071707}
17081708
17091709int MKDirpSync (uv_loop_t * loop,
0 commit comments