Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/vcpkg/base/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ namespace vcpkg::Files
/// <summary>Read text lines from a file</summary>
/// <remarks>Lines will have up to one trailing carriage-return character stripped (CRLF)</remarks>
virtual Expected<std::vector<std::string>> read_lines(const fs::path& file_path) const = 0;
std::vector<std::string> read_lines(const fs::path& file_path, LineInfo linfo) const;
virtual fs::path find_file_recursively_up(const fs::path& starting_dir, const fs::path& filename) const = 0;
virtual std::vector<fs::path> get_files_recursive(const fs::path& dir) const = 0;
virtual std::vector<fs::path> get_files_non_recursive(const fs::path& dir) const = 0;
Expand Down
16 changes: 14 additions & 2 deletions src/vcpkg/base/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,18 @@ namespace vcpkg::Files
}
}

std::vector<std::string> Filesystem::read_lines(const fs::path& path, LineInfo linfo) const
{
auto maybe_lines = this->read_lines(path);
if (auto p = maybe_lines.get())
{
return std::move(*p);
}

Checks::exit_with_message(
linfo, "error reading file: %s: %s", fs::u8string(path), maybe_lines.error().message());
}

std::string Filesystem::read_contents(const fs::path& path, LineInfo linfo) const
{
auto maybe_contents = this->read_contents(path);
Expand Down Expand Up @@ -733,6 +745,7 @@ namespace vcpkg::Files
std::fstream file_stream(file_path, std::ios_base::in | std::ios_base::binary);
if (file_stream.fail())
{
Debug::print("Failed to open: ", fs::u8string(file_path), '\n');
return std::make_error_code(std::errc::no_such_file_or_directory);
}

Expand All @@ -756,10 +769,9 @@ namespace vcpkg::Files
std::fstream file_stream(file_path, std::ios_base::in | std::ios_base::binary);
if (file_stream.fail())
{
Debug::print("Missing path: ", fs::u8string(file_path), '\n');
Debug::print("Failed to open: ", fs::u8string(file_path), '\n');
return std::make_error_code(std::errc::no_such_file_or_directory);
}

std::vector<std::string> output;
std::string line;
while (std::getline(file_stream, line))
Expand Down
3 changes: 1 addition & 2 deletions src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,7 @@ namespace vcpkg::Build
#endif

auto& helpers = paths.get_cmake_script_hashes();
auto portfile_contents =
fs.read_contents(port_dir / fs::u8path("portfile.cmake")).value_or_exit(VCPKG_LINE_INFO);
auto portfile_contents = fs.read_contents(port_dir / fs::u8path("portfile.cmake"), VCPKG_LINE_INFO);
for (auto&& helper : helpers)
{
if (Strings::case_insensitive_ascii_contains(portfile_contents, helper.first))
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.upload-metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace vcpkg::Commands::UploadMetrics
{
(void)args.parse_arguments(COMMAND_STRUCTURE);
const auto& payload_path = args.command_arguments[0];
auto payload = fs.read_contents(payload_path).value_or_exit(VCPKG_LINE_INFO);
auto payload = fs.read_contents(payload_path, VCPKG_LINE_INFO);
Metrics::g_metrics.lock()->upload(payload);
Checks::exit_success(VCPKG_LINE_INFO);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ namespace vcpkg::Export
action.spec.triplet().to_string(),
raw_exported_dir_path / "installed" / "vcpkg" / "info" / (binary_paragraph.fullstem() + ".list"));

auto lines = fs.read_lines(paths.listfile_path(binary_paragraph)).value_or_exit(VCPKG_LINE_INFO);
auto lines = fs.read_lines(paths.listfile_path(binary_paragraph), VCPKG_LINE_INFO);
std::vector<fs::path> files;
for (auto&& suffix : lines)
{
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/statusparagraphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ namespace vcpkg
{
iobj.insert("usage", Json::Value::string(std::move(usage.message)));
}
auto owns_files = fs.read_lines(paths.listfile_path(ipv.core->package)).value_or_exit(VCPKG_LINE_INFO);
auto owns_files = fs.read_lines(paths.listfile_path(ipv.core->package), VCPKG_LINE_INFO);
Json::Array owns;
for (auto&& owns_file : owns_files)
owns.push_back(Json::Value::string(std::move(owns_file)));
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace vcpkg
static const std::string XML_VERSION = "2";
static const fs::path XML_PATH = paths.scripts / "vcpkgTools.xml";
static const std::regex XML_VERSION_REGEX{R"###(<tools[\s]+version="([^"]+)">)###"};
static const std::string XML = paths.get_filesystem().read_contents(XML_PATH).value_or_exit(VCPKG_LINE_INFO);
static const std::string XML = paths.get_filesystem().read_contents(XML_PATH, VCPKG_LINE_INFO);
std::smatch match_xml_version;
const bool has_xml_version = std::regex_search(XML.cbegin(), XML.cend(), match_xml_version, XML_VERSION_REGEX);
Checks::check_exit(VCPKG_LINE_INFO,
Expand Down
3 changes: 1 addition & 2 deletions src/vcpkg/vcpkglib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ namespace vcpkg
}

const fs::path listfile_path = paths.listfile_path(pgh->package);
std::vector<std::string> installed_files_of_current_pgh =
fs.read_lines(listfile_path).value_or_exit(VCPKG_LINE_INFO);
std::vector<std::string> installed_files_of_current_pgh = fs.read_lines(listfile_path, VCPKG_LINE_INFO);
Strings::trim_all_and_remove_whitespace_strings(&installed_files_of_current_pgh);
upgrade_to_slash_terminated_sorted_format(fs, &installed_files_of_current_pgh, listfile_path);

Expand Down