Skip to content

Commit 5a30615

Browse files
authored
Fix try_load_port to match its documented interface. (#1533)
The last two paths in try_load_port translated a nonexistent port directory or missing CONTROL file into errors, which is the try_load_port_required interface. No path returned the "nullptr scfl" result. The only caller of try_load_port in registries.cpp therefore clearly wanted the "_required" behavior.
1 parent 9828694 commit 5a30615

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

include/vcpkg/paragraphs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace vcpkg::Paragraphs
3535
// If an error occurs, the Expected will be in the error state.
3636
// Otherwise, if the port is known, the maybe_scfl.get()->source_control_file contains the loaded port information.
3737
// Otherwise, maybe_scfl.get()->source_control_file is nullptr.
38-
PortLoadResult try_load_port(const ReadOnlyFilesystem& fs, StringView port_name, const PortLocation& port_location);
38+
PortLoadResult try_load_port(const ReadOnlyFilesystem& fs, const PortLocation& port_location);
3939
// Identical to try_load_port, but the port unknown condition is mapped to an error.
4040
PortLoadResult try_load_port_required(const ReadOnlyFilesystem& fs,
4141
StringView port_name,

src/vcpkg/paragraphs.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ namespace vcpkg::Paragraphs
386386
});
387387
}
388388

389-
PortLoadResult try_load_port(const ReadOnlyFilesystem& fs, StringView port_name, const PortLocation& port_location)
389+
PortLoadResult try_load_port(const ReadOnlyFilesystem& fs, const PortLocation& port_location)
390390
{
391391
StatsTimer timer(g_load_ports_stats);
392392

@@ -441,34 +441,34 @@ namespace vcpkg::Paragraphs
441441
std::string{}};
442442
}
443443

444-
if (fs.exists(port_location.port_directory, IgnoreErrors{}))
445-
{
446-
return PortLoadResult{LocalizedString::from_raw(port_location.port_directory)
447-
.append_raw(": ")
448-
.append_raw(ErrorPrefix)
449-
.append(msgPortMissingManifest2, msg::package_name = port_name),
450-
std::string{}};
451-
}
452-
453-
return PortLoadResult{LocalizedString::from_raw(port_location.port_directory)
454-
.append_raw(": ")
455-
.append_raw(ErrorPrefix)
456-
.append(msgPortDoesNotExist, msg::package_name = port_name),
457-
std::string{}};
444+
return PortLoadResult{SourceControlFileAndLocation{}, std::string{}};
458445
}
459446

460447
PortLoadResult try_load_port_required(const ReadOnlyFilesystem& fs,
461448
StringView port_name,
462449
const PortLocation& port_location)
463450
{
464-
auto load_result = try_load_port(fs, port_name, port_location);
451+
auto load_result = try_load_port(fs, port_location);
465452
auto maybe_res = load_result.maybe_scfl.get();
466453
if (maybe_res)
467454
{
468455
auto res = maybe_res->source_control_file.get();
469456
if (!res)
470457
{
471-
load_result.maybe_scfl = msg::format_error(msgPortDoesNotExist, msg::package_name = port_name);
458+
if (fs.exists(port_location.port_directory, IgnoreErrors{}))
459+
{
460+
load_result.maybe_scfl = LocalizedString::from_raw(port_location.port_directory)
461+
.append_raw(": ")
462+
.append_raw(ErrorPrefix)
463+
.append(msgPortMissingManifest2, msg::package_name = port_name);
464+
}
465+
else
466+
{
467+
load_result.maybe_scfl = LocalizedString::from_raw(port_location.port_directory)
468+
.append_raw(": ")
469+
.append_raw(ErrorPrefix)
470+
.append(msgPortDoesNotExist, msg::package_name = port_name);
471+
}
472472
}
473473
}
474474

src/vcpkg/registries.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ namespace
497497
return m_scfls.get_lazy(path, [&, this]() {
498498
std::string spdx_location = "git+https://github.com/Microsoft/vcpkg#ports/";
499499
spdx_location.append(port_name.data(), port_name.size());
500-
return Paragraphs::try_load_port(m_fs, port_name, PortLocation{path, std::move(spdx_location)})
500+
return Paragraphs::try_load_port_required(m_fs, port_name, PortLocation{path, std::move(spdx_location)})
501501
.maybe_scfl;
502502
});
503503
}

0 commit comments

Comments
 (0)