@@ -3260,24 +3260,24 @@ 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 = " src and dest cannot be the same %s" ;
3264+ return THROW_ERR_FS_CP_EINVAL (env, message, dest_path_str);
32653265 }
32663266
32673267 const bool dest_is_dir =
32683268 dest_status.type () == std::filesystem::file_type::directory;
32693269 if (src_is_dir && !dest_is_dir) {
3270- std::string message =
3270+ static constexpr const char * message =
32713271 " Cannot overwrite non-directory %s with directory %s" ;
32723272 return THROW_ERR_FS_CP_DIR_TO_NON_DIR (
3273- env, message. c_str () , dest_path_str, src_path_str);
3273+ env, message, dest_path_str, src_path_str);
32743274 }
32753275
32763276 if (!src_is_dir && dest_is_dir) {
3277- std::string message =
3277+ static constexpr const char * message =
32783278 " Cannot overwrite directory %s with non-directory %s" ;
32793279 return THROW_ERR_FS_CP_NON_DIR_TO_DIR (
3280- env, message. c_str () , dest_path_str, src_path_str);
3280+ env, message, dest_path_str, src_path_str);
32813281 }
32823282 }
32833283
@@ -3286,9 +3286,10 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
32863286 }
32873287 // Check if dest_path is a subdirectory of src_path.
32883288 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" ;
3289+ static constexpr const char * message =
3290+ " Cannot copy %s to a subdirectory of self %s" ;
32903291 return THROW_ERR_FS_CP_EINVAL (
3291- env, message. c_str () , src_path_str, dest_path_str);
3292+ env, message, src_path_str, dest_path_str);
32923293 }
32933294
32943295 auto dest_parent = dest_path.parent_path ();
@@ -3299,9 +3300,10 @@ 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+ static constexpr const char * message =
3304+ " Cannot copy %s to a subdirectory of self %s" ;
33033305 return THROW_ERR_FS_CP_EINVAL (
3304- env, message. c_str () , src_path_str, dest_path_str);
3306+ env, message, src_path_str, dest_path_str);
33053307 }
33063308
33073309 // If equivalent fails, it's highly likely that dest_parent does not exist
@@ -3313,23 +3315,23 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
33133315 }
33143316
33153317 if (src_is_dir && !recursive) {
3316- std::string message =
3318+ static constexpr const char * message =
33173319 " Recursive option not enabled, cannot copy a directory: %s" ;
3318- return THROW_ERR_FS_EISDIR (env, message. c_str () , src_path_str);
3320+ return THROW_ERR_FS_EISDIR (env, message, src_path_str);
33193321 }
33203322
33213323 switch (src_status.type ()) {
33223324 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);
3325+ static constexpr const char * message = " Cannot copy a socket file: %s" ;
3326+ return THROW_ERR_FS_CP_SOCKET (env, message, dest_path_str);
33253327 }
33263328 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);
3329+ static constexpr const char * message = " Cannot copy a FIFO pipe: %s" ;
3330+ return THROW_ERR_FS_CP_FIFO_PIPE (env, message, dest_path_str);
33293331 }
33303332 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);
3333+ static constexpr const char * message = " 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