diff --git a/src/node_file.cc b/src/node_file.cc index 6110de9448e3c0..5c9114091c609f 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -3260,24 +3260,25 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo& args) { if (!error_code) { // Check if src and dest are identical. if (std::filesystem::equivalent(src_path, dest_path)) { - std::string message = "src and dest cannot be the same %s"; - return THROW_ERR_FS_CP_EINVAL(env, message.c_str(), dest_path_str); + static constexpr const char* message = + "src and dest cannot be the same %s"; + return THROW_ERR_FS_CP_EINVAL(env, message, dest_path_str); } const bool dest_is_dir = dest_status.type() == std::filesystem::file_type::directory; if (src_is_dir && !dest_is_dir) { - std::string message = + static constexpr const char* message = "Cannot overwrite non-directory %s with directory %s"; return THROW_ERR_FS_CP_DIR_TO_NON_DIR( - env, message.c_str(), dest_path_str, src_path_str); + env, message, dest_path_str, src_path_str); } if (!src_is_dir && dest_is_dir) { - std::string message = + static constexpr const char* message = "Cannot overwrite directory %s with non-directory %s"; return THROW_ERR_FS_CP_NON_DIR_TO_DIR( - env, message.c_str(), dest_path_str, src_path_str); + env, message, dest_path_str, src_path_str); } } @@ -3286,9 +3287,9 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo& args) { } // Check if dest_path is a subdirectory of src_path. if (src_is_dir && dest_path_str.starts_with(src_path_str)) { - std::string message = "Cannot copy %s to a subdirectory of self %s"; - return THROW_ERR_FS_CP_EINVAL( - env, message.c_str(), src_path_str, dest_path_str); + static constexpr const char* message = + "Cannot copy %s to a subdirectory of self %s"; + return THROW_ERR_FS_CP_EINVAL(env, message, src_path_str, dest_path_str); } auto dest_parent = dest_path.parent_path(); @@ -3299,9 +3300,9 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo& args) { dest_parent.parent_path() != dest_parent) { if (std::filesystem::equivalent( src_path, dest_path.parent_path(), error_code)) { - std::string message = "Cannot copy %s to a subdirectory of self %s"; - return THROW_ERR_FS_CP_EINVAL( - env, message.c_str(), src_path_str, dest_path_str); + static constexpr const char* message = + "Cannot copy %s to a subdirectory of self %s"; + return THROW_ERR_FS_CP_EINVAL(env, message, src_path_str, dest_path_str); } // If equivalent fails, it's highly likely that dest_parent does not exist @@ -3313,23 +3314,24 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo& args) { } if (src_is_dir && !recursive) { - std::string message = + static constexpr const char* message = "Recursive option not enabled, cannot copy a directory: %s"; - return THROW_ERR_FS_EISDIR(env, message.c_str(), src_path_str); + return THROW_ERR_FS_EISDIR(env, message, src_path_str); } switch (src_status.type()) { case std::filesystem::file_type::socket: { - std::string message = "Cannot copy a socket file: %s"; - return THROW_ERR_FS_CP_SOCKET(env, message.c_str(), dest_path_str); + static constexpr const char* message = "Cannot copy a socket file: %s"; + return THROW_ERR_FS_CP_SOCKET(env, message, dest_path_str); } case std::filesystem::file_type::fifo: { - std::string message = "Cannot copy a FIFO pipe: %s"; - return THROW_ERR_FS_CP_FIFO_PIPE(env, message.c_str(), dest_path_str); + static constexpr const char* message = "Cannot copy a FIFO pipe: %s"; + return THROW_ERR_FS_CP_FIFO_PIPE(env, message, dest_path_str); } case std::filesystem::file_type::unknown: { - std::string message = "Cannot copy an unknown file type: %s"; - return THROW_ERR_FS_CP_UNKNOWN(env, message.c_str(), dest_path_str); + static constexpr const char* message = + "Cannot copy an unknown file type: %s"; + return THROW_ERR_FS_CP_UNKNOWN(env, message, dest_path_str); } default: break;