Skip to content

Commit 77abfd0

Browse files
committed
Fix read operations like list on readonly filesystems.
Resolves microsoft/vcpkg#10812
1 parent d26341e commit 77abfd0

13 files changed

+149
-81
lines changed

include/vcpkg/vcpkglib.h

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

1414
namespace vcpkg
1515
{
16-
StatusParagraphs database_load_check(const Filesystem& fs, const InstalledPaths& installed);
16+
StatusParagraphs database_load(const ReadOnlyFilesystem& fs, const InstalledPaths& installed);
17+
StatusParagraphs database_load_collapse(const Filesystem& fs, const InstalledPaths& installed);
1718

1819
void write_update(const Filesystem& fs, const InstalledPaths& installed, const StatusParagraph& p);
1920

@@ -24,9 +25,12 @@ namespace vcpkg
2425
};
2526

2627
std::vector<InstalledPackageView> get_installed_ports(const StatusParagraphs& status_db);
27-
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const Filesystem& fs,
28+
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const ReadOnlyFilesystem& fs,
2829
const InstalledPaths& installed,
2930
const StatusParagraphs& status_db);
31+
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files_and_upgrade(const Filesystem& fs,
32+
const InstalledPaths& installed,
33+
const StatusParagraphs& status_db);
3034

3135
std::string shorten_text(StringView desc, const size_t length);
3236
} // 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);
@@ -617,6 +617,7 @@ namespace vcpkg
617617
this_install.current_summary.build_result.emplace(std::move(result));
618618
}
619619

620+
database_load_collapse(fs, paths.installed());
620621
msg::println(msgTotalInstallTime, msg::elapsed = timer.to_string());
621622
return InstallSummary{std::move(results)};
622623
}
@@ -1286,7 +1287,7 @@ namespace vcpkg
12861287

12871288
// create the plan
12881289
msg::println(msgComputingInstallPlan);
1289-
StatusParagraphs status_db = database_load_check(fs, paths.installed());
1290+
StatusParagraphs status_db = database_load_collapse(fs, paths.installed());
12901291

12911292
// Note: action_plan will hold raw pointers to SourceControlFileLocations from this map
12921293
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
@@ -148,7 +148,7 @@ namespace
148148

149149
std::vector<std::string> valid_arguments(const VcpkgPaths& paths)
150150
{
151-
const StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
151+
const StatusParagraphs status_db = database_load(paths.get_filesystem(), paths.installed());
152152
auto installed_packages = get_installed_ports(status_db);
153153

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

184-
StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
184+
StatusParagraphs status_db = database_load_collapse(paths.get_filesystem(), paths.installed());
185185
std::vector<PackageSpec> specs;
186186
if (Util::Sets::contains(options.switches, SwitchOutdated))
187187
{
@@ -299,6 +299,7 @@ namespace vcpkg
299299
}
300300
}
301301

302+
database_load_collapse(fs, paths.installed());
302303
Checks::exit_success(VCPKG_LINE_INFO);
303304
}
304305
}

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)