Skip to content

Commit

Permalink
Avoid writing the status database for read-only commands.
Browse files Browse the repository at this point in the history
Resolves microsoft/vcpkg#10812

Depends on microsoft#1529
Extracted from  microsoft#1514

Splits database_load_check into database_load, which merely loads the current database, and database_load_collapse, which additionally smashes any outstanding update files.
Splits get_installed_files into get_installed_files and get_installed_files_and_upgrade. The former avoids the format conversion and thus does not need to write.

Reading commands database_load / get_installed_files:
* export
* list
* owns
* package_info
* update

Writing commands which use database_load_collapse / get_installed_files_and_upgrade. Also intend to call database_load_collapse at the end after successful completion so that the status file has all update records merged in where possible.
* build
* ci
* install
* remove
* set-installed
* upgrade
  • Loading branch information
BillyONeal committed Oct 24, 2024
1 parent bd544b0 commit 412ef61
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 83 deletions.
2 changes: 2 additions & 0 deletions include/vcpkg/base/contractual-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ 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 FileStatusOld = "status-old";
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 @@ -132,7 +132,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 @@ -502,7 +502,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 @@ -619,6 +619,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 @@ -1288,7 +1289,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 @@ -150,7 +150,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 @@ -183,7 +183,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 @@ -301,6 +301,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 @@ -211,7 +211,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,
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 @@ -76,7 +76,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

0 comments on commit 412ef61

Please sign in to comment.