Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid writing the status database for read-only commands. #1531

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions include/vcpkg/base/contractual-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ namespace vcpkg
inline constexpr StringLiteral FilePortfileDotCMake = "portfile.cmake";
inline constexpr StringLiteral FileShare = "share";
inline constexpr StringLiteral FileStatus = "status";
inline constexpr StringLiteral FileStatusNew = "status-new";
inline constexpr StringLiteral FileTools = "tools";
inline constexpr StringLiteral FileUpdates = "updates";
inline constexpr StringLiteral FileUsage = "usage";
Expand Down
15 changes: 13 additions & 2 deletions include/vcpkg/vcpkglib.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@

namespace vcpkg
{
StatusParagraphs database_load_check(const Filesystem& fs, const InstalledPaths& installed);
// Read the status database
StatusParagraphs database_load(const ReadOnlyFilesystem& fs, const InstalledPaths& installed);
// Read the status database, and collapse update records into the current status file
StatusParagraphs database_load_collapse(const Filesystem& fs, const InstalledPaths& installed);

// Adds an update record
void write_update(const Filesystem& fs, const InstalledPaths& installed, const StatusParagraph& p);

struct StatusParagraphAndAssociatedFiles
Expand All @@ -24,9 +28,16 @@ namespace vcpkg
};

std::vector<InstalledPackageView> get_installed_ports(const StatusParagraphs& status_db);
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const Filesystem& fs,

// Reads the installed files from the status database.
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const ReadOnlyFilesystem& fs,
const InstalledPaths& installed,
const StatusParagraphs& status_db);
// Reads the installed files from the status database, converting installed file lists to the current version if
// necessary.
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files_and_upgrade(const Filesystem& fs,
const InstalledPaths& installed,
const StatusParagraphs& status_db);

std::string shorten_text(StringView desc, const size_t length);
} // namespace vcpkg
2 changes: 1 addition & 1 deletion src/vcpkg/commands.build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace vcpkg
auto& var_provider = *var_provider_storage;
var_provider.load_dep_info_vars({{spec}}, host_triplet);

StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());
auto action_plan = create_feature_install_plan(
provider,
var_provider,
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.ci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ namespace vcpkg
}
else
{
StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());
auto already_installed = adjust_action_plan_to_status_db(action_plan, status_db);
Util::erase_if(already_installed,
[&](auto& spec) { return Util::Sets::contains(split_specs->known, spec); });
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ namespace vcpkg
Triplet host_triplet)
{
(void)host_triplet;
const StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
const StatusParagraphs status_db = database_load(paths.get_filesystem(), paths.installed());
const auto opts = handle_export_command_arguments(paths, args, default_triplet, status_db);

// Load ports from ports dirs
Expand Down
5 changes: 3 additions & 2 deletions src/vcpkg/commands.install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ namespace vcpkg
const auto package_dir = paths.package_dir(bcf.core_paragraph.spec);
Triplet triplet = bcf.core_paragraph.spec.triplet();
const std::vector<StatusParagraphAndAssociatedFiles> pgh_and_files =
get_installed_files(fs, installed, *status_db);
get_installed_files_and_upgrade(fs, installed, *status_db);

const SortedVector<std::string> package_files = build_list_of_package_files(fs, package_dir);
const SortedVector<file_pack> installed_files = build_list_of_installed_files(pgh_and_files, triplet);
Expand Down Expand Up @@ -617,6 +617,7 @@ namespace vcpkg
this_install.current_summary.build_result.emplace(std::move(result));
}

database_load_collapse(fs, paths.installed());
msg::println(msgTotalInstallTime, msg::elapsed = timer.to_string());
return InstallSummary{std::move(results)};
}
Expand Down Expand Up @@ -1284,7 +1285,7 @@ namespace vcpkg

// create the plan
msg::println(msgComputingInstallPlan);
StatusParagraphs status_db = database_load_check(fs, paths.installed());
StatusParagraphs status_db = database_load_collapse(fs, paths.installed());

// Note: action_plan will hold raw pointers to SourceControlFileLocations from this map
auto action_plan = create_feature_install_plan(provider, var_provider, specs, status_db, create_options);
Expand Down
3 changes: 2 additions & 1 deletion src/vcpkg/commands.list.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <vcpkg/base/contractual-constants.h>
#include <vcpkg/base/files.h>
#include <vcpkg/base/strings.h>
#include <vcpkg/base/util.h>

Expand Down Expand Up @@ -103,7 +104,7 @@ namespace vcpkg
msg::default_output_stream = OutputStream::StdErr;
const ParsedArguments options = args.parse_arguments(CommandListMetadata);

const StatusParagraphs status_paragraphs = database_load_check(paths.get_filesystem(), paths.installed());
const StatusParagraphs status_paragraphs = database_load(paths.get_filesystem(), paths.installed());
auto installed_ipv = get_installed_ports(status_paragraphs);

const auto output_json = Util::Sets::contains(options.switches, SwitchXJson);
Expand Down
6 changes: 4 additions & 2 deletions src/vcpkg/commands.owns.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <vcpkg/base/files.h>

#include <vcpkg/commands.owns.h>
#include <vcpkg/statusparagraphs.h>
#include <vcpkg/vcpkgcmdarguments.h>
Expand All @@ -8,7 +10,7 @@ using namespace vcpkg;

namespace
{
void search_file(const Filesystem& fs,
void search_file(const ReadOnlyFilesystem& fs,
const InstalledPaths& installed,
const std::string& file_substr,
const StatusParagraphs& status_db)
Expand Down Expand Up @@ -46,7 +48,7 @@ namespace vcpkg
void command_owns_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
{
const auto parsed = args.parse_arguments(CommandOwnsMetadata);
const StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
const StatusParagraphs status_db = database_load(paths.get_filesystem(), paths.installed());
search_file(paths.get_filesystem(), paths.installed(), parsed.command_arguments[0], status_db);
Checks::exit_success(VCPKG_LINE_INFO);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.package-info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace vcpkg
auto& fs = paths.get_filesystem();
if (installed)
{
const StatusParagraphs status_paragraphs = database_load_check(fs, paths.installed());
const StatusParagraphs status_paragraphs = database_load(fs, paths.installed());
std::set<PackageSpec> specs_written;
std::vector<PackageSpec> specs_to_write;
for (auto&& arg : options.command_arguments)
Expand Down
5 changes: 3 additions & 2 deletions src/vcpkg/commands.remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace

std::vector<std::string> valid_arguments(const VcpkgPaths& paths)
{
const StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
const StatusParagraphs status_db = database_load(paths.get_filesystem(), paths.installed());
auto installed_packages = get_installed_ports(status_db);

return Util::fmap(installed_packages, [](auto&& pgh) -> std::string { return pgh.spec().to_string(); });
Expand Down Expand Up @@ -181,7 +181,7 @@ namespace vcpkg
}
const ParsedArguments options = args.parse_arguments(CommandRemoveMetadata);

StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());
std::vector<PackageSpec> specs;
if (Util::Sets::contains(options.switches, SwitchOutdated))
{
Expand Down Expand Up @@ -298,6 +298,7 @@ namespace vcpkg
}
}

database_load_collapse(fs, paths.installed());
Checks::exit_success(VCPKG_LINE_INFO);
}
}
2 changes: 1 addition & 1 deletion src/vcpkg/commands.set-installed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ namespace vcpkg
}

// currently (or once) installed specifications
auto status_db = database_load_check(fs, paths.installed());
auto status_db = database_load_collapse(fs, paths.installed());
adjust_action_plan_to_status_db(action_plan, status_db);

print_plan(action_plan, paths.builtin_ports_directory());
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace vcpkg
msg::println(msgLocalPortfileVersion);

auto& fs = paths.get_filesystem();
const StatusParagraphs status_db = database_load_check(fs, paths.installed());
const StatusParagraphs status_db = database_load(fs, paths.installed());

auto registry_set = paths.make_registry_set();
PathsPortFileProvider provider(*registry_set, make_overlay_provider(fs, paths.overlay_ports));
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace vcpkg
const CreateUpgradePlanOptions create_upgrade_plan_options{
nullptr, host_triplet, paths.packages(), unsupported_port_action};

StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());

// Load ports from ports dirs
auto& fs = paths.get_filesystem();
Expand Down
Loading
Loading