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