Skip to content

Commit 412ef61

Browse files
committed
Avoid writing the status database for read-only commands.
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
1 parent bd544b0 commit 412ef61

14 files changed

+160
-83
lines changed

include/vcpkg/base/contractual-constants.h

+2
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ namespace vcpkg
344344
inline constexpr StringLiteral FilePortfileDotCMake = "portfile.cmake";
345345
inline constexpr StringLiteral FileShare = "share";
346346
inline constexpr StringLiteral FileStatus = "status";
347+
inline constexpr StringLiteral FileStatusNew = "status-new";
348+
inline constexpr StringLiteral FileStatusOld = "status-old";
347349
inline constexpr StringLiteral FileTools = "tools";
348350
inline constexpr StringLiteral FileUpdates = "updates";
349351
inline constexpr StringLiteral FileUsage = "usage";

include/vcpkg/vcpkglib.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313

1414
namespace vcpkg
1515
{
16-
StatusParagraphs database_load_check(const Filesystem& fs, const InstalledPaths& installed);
16+
// Read the status database
17+
StatusParagraphs database_load(const ReadOnlyFilesystem& fs, const InstalledPaths& installed);
18+
// Read the status database, and collapse update records into the current status file
19+
StatusParagraphs database_load_collapse(const Filesystem& fs, const InstalledPaths& installed);
1720

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

2024
struct StatusParagraphAndAssociatedFiles
@@ -24,9 +28,16 @@ namespace vcpkg
2428
};
2529

2630
std::vector<InstalledPackageView> get_installed_ports(const StatusParagraphs& status_db);
27-
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const Filesystem& fs,
31+
32+
// Reads the installed files from the status database.
33+
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const ReadOnlyFilesystem& fs,
2834
const InstalledPaths& installed,
2935
const StatusParagraphs& status_db);
36+
// Reads the installed files from the status database, converting installed file lists to the current version if
37+
// necessary.
38+
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files_and_upgrade(const Filesystem& fs,
39+
const InstalledPaths& installed,
40+
const StatusParagraphs& status_db);
3041

3142
std::string shorten_text(StringView desc, const size_t length);
3243
} // namespace vcpkg

src/vcpkg/commands.build.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ namespace vcpkg
132132
auto& var_provider = *var_provider_storage;
133133
var_provider.load_dep_info_vars({{spec}}, host_triplet);
134134

135-
StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
135+
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());
136136
auto action_plan = create_feature_install_plan(
137137
provider,
138138
var_provider,

src/vcpkg/commands.ci.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ namespace vcpkg
502502
}
503503
else
504504
{
505-
StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
505+
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());
506506
auto already_installed = adjust_action_plan_to_status_db(action_plan, status_db);
507507
Util::erase_if(already_installed,
508508
[&](auto& spec) { return Util::Sets::contains(split_specs->known, spec); });

src/vcpkg/commands.export.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ namespace vcpkg
596596
Triplet host_triplet)
597597
{
598598
(void)host_triplet;
599-
const StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
599+
const StatusParagraphs status_db = database_load(paths.get_filesystem(), paths.installed());
600600
const auto opts = handle_export_command_arguments(paths, args, default_triplet, status_db);
601601

602602
// Load ports from ports dirs

src/vcpkg/commands.install.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ namespace vcpkg
224224
const auto package_dir = paths.package_dir(bcf.core_paragraph.spec);
225225
Triplet triplet = bcf.core_paragraph.spec.triplet();
226226
const std::vector<StatusParagraphAndAssociatedFiles> pgh_and_files =
227-
get_installed_files(fs, installed, *status_db);
227+
get_installed_files_and_upgrade(fs, installed, *status_db);
228228

229229
const SortedVector<std::string> package_files = build_list_of_package_files(fs, package_dir);
230230
const SortedVector<file_pack> installed_files = build_list_of_installed_files(pgh_and_files, triplet);
@@ -619,6 +619,7 @@ namespace vcpkg
619619
this_install.current_summary.build_result.emplace(std::move(result));
620620
}
621621

622+
database_load_collapse(fs, paths.installed());
622623
msg::println(msgTotalInstallTime, msg::elapsed = timer.to_string());
623624
return InstallSummary{std::move(results)};
624625
}
@@ -1288,7 +1289,7 @@ namespace vcpkg
12881289

12891290
// create the plan
12901291
msg::println(msgComputingInstallPlan);
1291-
StatusParagraphs status_db = database_load_check(fs, paths.installed());
1292+
StatusParagraphs status_db = database_load_collapse(fs, paths.installed());
12921293

12931294
// Note: action_plan will hold raw pointers to SourceControlFileLocations from this map
12941295
auto action_plan = create_feature_install_plan(provider, var_provider, specs, status_db, create_options);

src/vcpkg/commands.list.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <vcpkg/base/contractual-constants.h>
2+
#include <vcpkg/base/files.h>
23
#include <vcpkg/base/strings.h>
34
#include <vcpkg/base/util.h>
45

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

106-
const StatusParagraphs status_paragraphs = database_load_check(paths.get_filesystem(), paths.installed());
107+
const StatusParagraphs status_paragraphs = database_load(paths.get_filesystem(), paths.installed());
107108
auto installed_ipv = get_installed_ports(status_paragraphs);
108109

109110
const auto output_json = Util::Sets::contains(options.switches, SwitchXJson);

src/vcpkg/commands.owns.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <vcpkg/base/files.h>
2+
13
#include <vcpkg/commands.owns.h>
24
#include <vcpkg/statusparagraphs.h>
35
#include <vcpkg/vcpkgcmdarguments.h>
@@ -8,7 +10,7 @@ using namespace vcpkg;
810

911
namespace
1012
{
11-
void search_file(const Filesystem& fs,
13+
void search_file(const ReadOnlyFilesystem& fs,
1214
const InstalledPaths& installed,
1315
const std::string& file_substr,
1416
const StatusParagraphs& status_db)
@@ -46,7 +48,7 @@ namespace vcpkg
4648
void command_owns_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
4749
{
4850
const auto parsed = args.parse_arguments(CommandOwnsMetadata);
49-
const StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
51+
const StatusParagraphs status_db = database_load(paths.get_filesystem(), paths.installed());
5052
search_file(paths.get_filesystem(), paths.installed(), parsed.command_arguments[0], status_db);
5153
Checks::exit_success(VCPKG_LINE_INFO);
5254
}

src/vcpkg/commands.package-info.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace vcpkg
6161
auto& fs = paths.get_filesystem();
6262
if (installed)
6363
{
64-
const StatusParagraphs status_paragraphs = database_load_check(fs, paths.installed());
64+
const StatusParagraphs status_paragraphs = database_load(fs, paths.installed());
6565
std::set<PackageSpec> specs_written;
6666
std::vector<PackageSpec> specs_to_write;
6767
for (auto&& arg : options.command_arguments)

src/vcpkg/commands.remove.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ namespace
150150

151151
std::vector<std::string> valid_arguments(const VcpkgPaths& paths)
152152
{
153-
const StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
153+
const StatusParagraphs status_db = database_load(paths.get_filesystem(), paths.installed());
154154
auto installed_packages = get_installed_ports(status_db);
155155

156156
return Util::fmap(installed_packages, [](auto&& pgh) -> std::string { return pgh.spec().to_string(); });
@@ -183,7 +183,7 @@ namespace vcpkg
183183
}
184184
const ParsedArguments options = args.parse_arguments(CommandRemoveMetadata);
185185

186-
StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
186+
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());
187187
std::vector<PackageSpec> specs;
188188
if (Util::Sets::contains(options.switches, SwitchOutdated))
189189
{
@@ -301,6 +301,7 @@ namespace vcpkg
301301
}
302302
}
303303

304+
database_load_collapse(fs, paths.installed());
304305
Checks::exit_success(VCPKG_LINE_INFO);
305306
}
306307
}

src/vcpkg/commands.set-installed.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ namespace vcpkg
211211
}
212212

213213
// currently (or once) installed specifications
214-
auto status_db = database_load_check(fs, paths.installed());
214+
auto status_db = database_load_collapse(fs, paths.installed());
215215
adjust_action_plan_to_status_db(action_plan, status_db);
216216

217217
print_plan(action_plan, paths.builtin_ports_directory());

src/vcpkg/commands.update.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace vcpkg
6565
msg::println(msgLocalPortfileVersion);
6666

6767
auto& fs = paths.get_filesystem();
68-
const StatusParagraphs status_db = database_load_check(fs, paths.installed());
68+
const StatusParagraphs status_db = database_load(fs, paths.installed());
6969

7070
auto registry_set = paths.make_registry_set();
7171
PathsPortFileProvider provider(*registry_set,

src/vcpkg/commands.upgrade.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace vcpkg
7676
const CreateUpgradePlanOptions create_upgrade_plan_options{
7777
nullptr, host_triplet, paths.packages(), unsupported_port_action};
7878

79-
StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
79+
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());
8080

8181
// Load ports from ports dirs
8282
auto& fs = paths.get_filesystem();

0 commit comments

Comments
 (0)