@@ -3260,24 +3260,25 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
32603260 if (!error_code) {
32613261 // Check if src and dest are identical.
32623262 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);
32653266 }
32663267
32673268 const bool dest_is_dir =
32683269 dest_status.type () == std::filesystem::file_type::directory;
32693270 if (src_is_dir && !dest_is_dir) {
3270- std::string message =
3271+ static constexpr const char * message =
32713272 " Cannot overwrite non-directory %s with directory %s" ;
32723273 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);
32743275 }
32753276
32763277 if (!src_is_dir && dest_is_dir) {
3277- std::string message =
3278+ static constexpr const char * message =
32783279 " Cannot overwrite directory %s with non-directory %s" ;
32793280 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);
32813282 }
32823283 }
32833284
@@ -3286,9 +3287,9 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
32863287 }
32873288 // Check if dest_path is a subdirectory of src_path.
32883289 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);
32923293 }
32933294
32943295 auto dest_parent = dest_path.parent_path ();
@@ -3299,9 +3300,9 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
32993300 dest_parent.parent_path () != dest_parent) {
33003301 if (std::filesystem::equivalent (
33013302 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);
33053306 }
33063307
33073308 // If equivalent fails, it's highly likely that dest_parent does not exist
@@ -3313,23 +3314,24 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
33133314 }
33143315
33153316 if (src_is_dir && !recursive) {
3316- std::string message =
3317+ static constexpr const char * message =
33173318 " 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);
33193320 }
33203321
33213322 switch (src_status.type ()) {
33223323 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);
33253326 }
33263327 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);
33293330 }
33303331 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);
33333335 }
33343336 default :
33353337 break ;
0 commit comments