@@ -3260,24 +3260,25 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
3260
3260
if (!error_code) {
3261
3261
// Check if src and dest are identical.
3262
3262
if (std::filesystem::equivalent (src_path, dest_path)) {
3263
- std::string message = " src and dest cannot be the same %s" ;
3264
- return THROW_ERR_FS_CP_EINVAL (env, message.c_str (), dest_path_str);
3263
+ static constexpr const char * message =
3264
+ " src and dest cannot be the same %s" ;
3265
+ return THROW_ERR_FS_CP_EINVAL (env, message, dest_path_str);
3265
3266
}
3266
3267
3267
3268
const bool dest_is_dir =
3268
3269
dest_status.type () == std::filesystem::file_type::directory;
3269
3270
if (src_is_dir && !dest_is_dir) {
3270
- std::string message =
3271
+ static constexpr const char * message =
3271
3272
" Cannot overwrite non-directory %s with directory %s" ;
3272
3273
return THROW_ERR_FS_CP_DIR_TO_NON_DIR (
3273
- env, message. c_str () , dest_path_str, src_path_str);
3274
+ env, message, dest_path_str, src_path_str);
3274
3275
}
3275
3276
3276
3277
if (!src_is_dir && dest_is_dir) {
3277
- std::string message =
3278
+ static constexpr const char * message =
3278
3279
" Cannot overwrite directory %s with non-directory %s" ;
3279
3280
return THROW_ERR_FS_CP_NON_DIR_TO_DIR (
3280
- env, message. c_str () , dest_path_str, src_path_str);
3281
+ env, message, dest_path_str, src_path_str);
3281
3282
}
3282
3283
}
3283
3284
@@ -3286,9 +3287,9 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
3286
3287
}
3287
3288
// Check if dest_path is a subdirectory of src_path.
3288
3289
if (src_is_dir && dest_path_str.starts_with (src_path_str)) {
3289
- std::string message = " Cannot copy %s to a subdirectory of self %s " ;
3290
- return THROW_ERR_FS_CP_EINVAL (
3291
- env, message. c_str () , src_path_str, dest_path_str);
3290
+ static constexpr const char * message =
3291
+ " Cannot copy %s to a subdirectory of self %s " ;
3292
+ return THROW_ERR_FS_CP_EINVAL ( env, message, src_path_str, dest_path_str);
3292
3293
}
3293
3294
3294
3295
auto dest_parent = dest_path.parent_path ();
@@ -3299,9 +3300,9 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
3299
3300
dest_parent.parent_path () != dest_parent) {
3300
3301
if (std::filesystem::equivalent (
3301
3302
src_path, dest_path.parent_path (), error_code)) {
3302
- std::string message = " Cannot copy %s to a subdirectory of self %s " ;
3303
- return THROW_ERR_FS_CP_EINVAL (
3304
- env, message. c_str () , src_path_str, dest_path_str);
3303
+ static constexpr const char * message =
3304
+ " Cannot copy %s to a subdirectory of self %s " ;
3305
+ return THROW_ERR_FS_CP_EINVAL ( env, message, src_path_str, dest_path_str);
3305
3306
}
3306
3307
3307
3308
// If equivalent fails, it's highly likely that dest_parent does not exist
@@ -3313,23 +3314,24 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
3313
3314
}
3314
3315
3315
3316
if (src_is_dir && !recursive) {
3316
- std::string message =
3317
+ static constexpr const char * message =
3317
3318
" Recursive option not enabled, cannot copy a directory: %s" ;
3318
- return THROW_ERR_FS_EISDIR (env, message. c_str () , src_path_str);
3319
+ return THROW_ERR_FS_EISDIR (env, message, src_path_str);
3319
3320
}
3320
3321
3321
3322
switch (src_status.type ()) {
3322
3323
case std::filesystem::file_type::socket: {
3323
- std::string message = " Cannot copy a socket file: %s" ;
3324
- return THROW_ERR_FS_CP_SOCKET (env, message. c_str () , dest_path_str);
3324
+ static constexpr const char * message = " Cannot copy a socket file: %s" ;
3325
+ return THROW_ERR_FS_CP_SOCKET (env, message, dest_path_str);
3325
3326
}
3326
3327
case std::filesystem::file_type::fifo: {
3327
- std::string message = " Cannot copy a FIFO pipe: %s" ;
3328
- return THROW_ERR_FS_CP_FIFO_PIPE (env, message. c_str () , dest_path_str);
3328
+ static constexpr const char * message = " Cannot copy a FIFO pipe: %s" ;
3329
+ return THROW_ERR_FS_CP_FIFO_PIPE (env, message, dest_path_str);
3329
3330
}
3330
3331
case std::filesystem::file_type::unknown: {
3331
- std::string message = " Cannot copy an unknown file type: %s" ;
3332
- return THROW_ERR_FS_CP_UNKNOWN (env, message.c_str (), dest_path_str);
3332
+ static constexpr const char * message =
3333
+ " Cannot copy an unknown file type: %s" ;
3334
+ return THROW_ERR_FS_CP_UNKNOWN (env, message, dest_path_str);
3333
3335
}
3334
3336
default :
3335
3337
break ;
0 commit comments