From c58acff42afd591762746538f0d2226ee63cbef0 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Fri, 10 Oct 2025 00:11:25 +0300 Subject: [PATCH] libfetchers: Remove toRealPath in SourceHutInputScheme::getRevFromRef This code had several issues: 1. Not going through the SourceAccessor means that we can only work with physical paths. 2. It did not actually check that the file exists. (std::ifstream does not check it by default). --- src/libfetchers/github.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index 3b723d7d8..a905bb384 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -548,13 +548,10 @@ struct SourceHutInputScheme : GitArchiveInputScheme std::string refUri; if (ref == "HEAD") { - auto file = store->toRealPath( - downloadFile(store, *input.settings, fmt("%s/HEAD", base_url), "source", headers).storePath); - std::ifstream is(file); - std::string line; - getline(is, line); + auto downloadFileResult = downloadFile(store, *input.settings, fmt("%s/HEAD", base_url), "source", headers); + auto contents = nix::ref(store->getFSAccessor(downloadFileResult.storePath))->readFile(CanonPath::root); - auto remoteLine = git::parseLsRemoteLine(line); + auto remoteLine = git::parseLsRemoteLine(getLine(contents).first); if (!remoteLine) { throw BadURL("in '%d', couldn't resolve HEAD ref '%d'", input.to_string(), ref); } @@ -564,9 +561,10 @@ struct SourceHutInputScheme : GitArchiveInputScheme } std::regex refRegex(refUri); - auto file = store->toRealPath( - downloadFile(store, *input.settings, fmt("%s/info/refs", base_url), "source", headers).storePath); - std::ifstream is(file); + auto downloadFileResult = + downloadFile(store, *input.settings, fmt("%s/info/refs", base_url), "source", headers); + auto contents = nix::ref(store->getFSAccessor(downloadFileResult.storePath))->readFile(CanonPath::root); + std::istringstream is(contents); std::string line; std::optional id;