@@ -3130,22 +3130,24 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
3130
3130
ToNamespacedPath (env, &src);
3131
3131
THROW_IF_INSUFFICIENT_PERMISSIONS (
3132
3132
env, permission::PermissionScope::kFileSystemRead , src.ToStringView ());
3133
- auto src_path = std::filesystem::path (src.ToStringView ());
3133
+
3134
+ auto src_path = std::filesystem::path (src.ToU8StringView ());
3134
3135
3135
3136
BufferValue dest (isolate, args[1 ]);
3136
3137
CHECK_NOT_NULL (*dest);
3137
3138
ToNamespacedPath (env, &dest);
3138
3139
THROW_IF_INSUFFICIENT_PERMISSIONS (
3139
3140
env, permission::PermissionScope::kFileSystemWrite , dest.ToStringView ());
3140
- auto dest_path = std::filesystem::path (dest.ToStringView ());
3141
3141
3142
+ auto dest_path = std::filesystem::path (dest.ToU8StringView ());
3142
3143
bool dereference = args[2 ]->IsTrue ();
3143
3144
bool recursive = args[3 ]->IsTrue ();
3144
3145
3145
3146
std::error_code error_code;
3146
3147
auto src_status = dereference
3147
3148
? std::filesystem::symlink_status (src_path, error_code)
3148
3149
: std::filesystem::status (src_path, error_code);
3150
+
3149
3151
if (error_code) {
3150
3152
#ifdef _WIN32
3151
3153
int errorno = uv_translate_sys_error (error_code.value ());
@@ -3169,34 +3171,41 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
3169
3171
if (!error_code) {
3170
3172
// Check if src and dest are identical.
3171
3173
if (std::filesystem::equivalent (src_path, dest_path)) {
3172
- std::string message =
3173
- " src and dest cannot be the same " + dest_path.string ();
3174
- return THROW_ERR_FS_CP_EINVAL (env, message.c_str ());
3174
+ std::u8string message =
3175
+ u8" src and dest cannot be the same " + dest_path.u8string ();
3176
+ return THROW_ERR_FS_CP_EINVAL (
3177
+ env, reinterpret_cast <const char *>(message.c_str ()));
3175
3178
}
3176
3179
3177
3180
const bool dest_is_dir =
3178
3181
dest_status.type () == std::filesystem::file_type::directory;
3179
3182
3180
3183
if (src_is_dir && !dest_is_dir) {
3181
- std::string message = " Cannot overwrite non-directory " +
3182
- src_path.string () + " with directory " +
3183
- dest_path.string ();
3184
- return THROW_ERR_FS_CP_DIR_TO_NON_DIR (env, message.c_str ());
3184
+ std::u8string message = u8" Cannot overwrite non-directory " +
3185
+ src_path.u8string () + u8" with directory " +
3186
+ dest_path.u8string ();
3187
+ return THROW_ERR_FS_CP_DIR_TO_NON_DIR (
3188
+ env, reinterpret_cast <const char *>(message.c_str ()));
3185
3189
}
3186
3190
3187
3191
if (!src_is_dir && dest_is_dir) {
3188
- std::string message = " Cannot overwrite directory " + dest_path.string () +
3189
- " with non-directory " + src_path.string ();
3190
- return THROW_ERR_FS_CP_NON_DIR_TO_DIR (env, message.c_str ());
3192
+ std::u8string message = u8" Cannot overwrite directory " +
3193
+ dest_path.u8string () + u8" with non-directory " +
3194
+ src_path.u8string ();
3195
+ return THROW_ERR_FS_CP_NON_DIR_TO_DIR (
3196
+ env, reinterpret_cast <const char *>(message.c_str ()));
3191
3197
}
3192
3198
}
3193
3199
3194
- std::string dest_path_str = dest_path.string ();
3200
+ std::u8string dest_path_str = dest_path.u8string ();
3201
+
3195
3202
// Check if dest_path is a subdirectory of src_path.
3196
- if (src_is_dir && dest_path_str.starts_with (src_path.string ())) {
3197
- std::string message = " Cannot copy " + src_path.string () +
3198
- " to a subdirectory of self " + dest_path.string ();
3199
- return THROW_ERR_FS_CP_EINVAL (env, message.c_str ());
3203
+ if (src_is_dir && dest_path_str.starts_with (src_path.u8string ())) {
3204
+ std::u8string message = u8" Cannot copy " + src_path.u8string () +
3205
+ u8" to a subdirectory of self " +
3206
+ dest_path.u8string ();
3207
+ return THROW_ERR_FS_CP_EINVAL (
3208
+ env, reinterpret_cast <const char *>(message.c_str ()));
3200
3209
}
3201
3210
3202
3211
auto dest_parent = dest_path.parent_path ();
@@ -3207,9 +3216,11 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
3207
3216
dest_parent.parent_path () != dest_parent) {
3208
3217
if (std::filesystem::equivalent (
3209
3218
src_path, dest_path.parent_path (), error_code)) {
3210
- std::string message = " Cannot copy " + src_path.string () +
3211
- " to a subdirectory of self " + dest_path.string ();
3212
- return THROW_ERR_FS_CP_EINVAL (env, message.c_str ());
3219
+ std::u8string message = u8" Cannot copy " + src_path.u8string () +
3220
+ u8" to a subdirectory of self " +
3221
+ dest_path.u8string ();
3222
+ return THROW_ERR_FS_CP_EINVAL (
3223
+ env, reinterpret_cast <const char *>(message.c_str ()));
3213
3224
}
3214
3225
3215
3226
// If equivalent fails, it's highly likely that dest_parent does not exist
@@ -3221,25 +3232,29 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
3221
3232
}
3222
3233
3223
3234
if (src_is_dir && !recursive) {
3224
- std::string message =
3225
- " Recursive option not enabled, cannot copy a directory: " +
3226
- src_path.string ();
3227
- return THROW_ERR_FS_EISDIR (env, message.c_str ());
3235
+ std::u8string message =
3236
+ u8" Recursive option not enabled, cannot copy a directory: " +
3237
+ src_path.u8string ();
3238
+ return THROW_ERR_FS_EISDIR (env,
3239
+ reinterpret_cast <const char *>(message.c_str ()));
3228
3240
}
3229
3241
3230
3242
switch (src_status.type ()) {
3231
3243
case std::filesystem::file_type::socket: {
3232
- std::string message = " Cannot copy a socket file: " + dest_path.string ();
3233
- return THROW_ERR_FS_CP_SOCKET (env, message.c_str ());
3244
+ std::u8string message = u8" Cannot copy a socket file: " + dest_path_str;
3245
+ return THROW_ERR_FS_CP_SOCKET (
3246
+ env, reinterpret_cast <const char *>(message.c_str ()));
3234
3247
}
3235
3248
case std::filesystem::file_type::fifo: {
3236
- std::string message = " Cannot copy a FIFO pipe: " + dest_path.string ();
3237
- return THROW_ERR_FS_CP_FIFO_PIPE (env, message.c_str ());
3249
+ std::u8string message = u8" Cannot copy a FIFO pipe: " + dest_path_str;
3250
+ return THROW_ERR_FS_CP_FIFO_PIPE (
3251
+ env, reinterpret_cast <const char *>(message.c_str ()));
3238
3252
}
3239
3253
case std::filesystem::file_type::unknown: {
3240
- std::string message =
3241
- " Cannot copy an unknown file type: " + dest_path.string ();
3242
- return THROW_ERR_FS_CP_UNKNOWN (env, message.c_str ());
3254
+ std::u8string message =
3255
+ u8" Cannot copy an unknown file type: " + dest_path_str;
3256
+ return THROW_ERR_FS_CP_UNKNOWN (
3257
+ env, reinterpret_cast <const char *>(message.c_str ()));
3243
3258
}
3244
3259
default :
3245
3260
break ;
0 commit comments