diff --git a/src/debug_utils-inl.h b/src/debug_utils-inl.h index db59efaf112ef7..e3db1ef15b96f2 100644 --- a/src/debug_utils-inl.h +++ b/src/debug_utils-inl.h @@ -23,6 +23,13 @@ concept StringConvertible = requires(T a) { a.ToString() } -> std::convertible_to; }; +// For std::filesystem::path and similar types +template +concept StringConvertibleFSPathLike = requires(T a) { + { + a.string() + } -> std::convertible_to; + }; struct ToStringHelper { template @@ -30,6 +37,12 @@ struct ToStringHelper { static std::string Convert(const T& value) { return value.ToString(); } + template + requires(StringConvertibleFSPathLike) && (!StringViewConvertible) && + (!StringConvertible) + static std::string Convert(const T& value) { + return value.string(); + } template requires StringViewConvertible static std::string_view Convert(const T& value) { diff --git a/src/node_file.cc b/src/node_file.cc index f0d512069c6dc6..f778cbb2fea1de 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -3526,12 +3526,10 @@ static void CpSyncCopyDir(const FunctionCallbackInfo& args) { if (!dereference && std::filesystem::is_directory(symlink_target) && isInsideDir(symlink_target, current_dest_symlink_target)) { - std::string message = + static constexpr const char* message = "Cannot copy %s to a subdirectory of self %s"; - THROW_ERR_FS_CP_EINVAL(env, - message.c_str(), - symlink_target.c_str(), - current_dest_symlink_target.c_str()); + THROW_ERR_FS_CP_EINVAL( + env, message, symlink_target, current_dest_symlink_target); return false; } @@ -3540,12 +3538,10 @@ static void CpSyncCopyDir(const FunctionCallbackInfo& args) { // and therefore a broken symlink would be created. if (std::filesystem::is_directory(dest_file_path) && isInsideDir(current_dest_symlink_target, symlink_target)) { - std::string message = "cannot overwrite %s with %s"; + static constexpr const char* message = + "cannot overwrite %s with %s"; THROW_ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY( - env, - message.c_str(), - current_dest_symlink_target.c_str(), - symlink_target.c_str()); + env, message, current_dest_symlink_target, symlink_target); return false; } @@ -3597,7 +3593,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo& args) { THROW_ERR_FS_CP_EEXIST(isolate, "[ERR_FS_CP_EEXIST]: Target already exists: " "cp returned EEXIST (%s already exists)", - dest_file_path.c_str()); + dest_file_path); return false; } env->ThrowStdErrException(error, "cp", dest_str.c_str());