Skip to content

Commit cd83dd5

Browse files
committed
Create a second Store::getFSAccessor for a single store object
This is sometimes easier / more performant to implement, and independently it is also a more convenient interface for many callers.
1 parent 5292b0e commit cd83dd5

26 files changed

+119
-59
lines changed

src/libfetchers/fetchers.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "nix/util/source-path.hh"
44
#include "nix/fetchers/fetch-to-store.hh"
55
#include "nix/util/json-utils.hh"
6-
#include "nix/fetchers/store-path-accessor.hh"
76
#include "nix/fetchers/fetch-settings.hh"
87

98
#include <nlohmann/json.hpp>
@@ -332,7 +331,8 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> sto
332331

333332
debug("using substituted/cached input '%s' in '%s'", to_string(), store->printStorePath(storePath));
334333

335-
auto accessor = makeStorePathAccessor(store, storePath);
334+
// We just ensured the store object was there
335+
auto accessor = ref{store->getFSAccessor(storePath)};
336336

337337
accessor->fingerprint = getFingerprint(store);
338338

src/libfetchers/github.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,8 @@ struct GitHubInputScheme : GitArchiveInputScheme
398398

399399
Headers headers = makeHeadersWithAuthTokens(*input.settings, host, input);
400400

401-
auto accessor = store->getFSAccessor();
402401
auto downloadResult = downloadFile(store, *input.settings, url, "source", headers);
403-
auto json = nlohmann::json::parse(accessor->readFile(CanonPath(downloadResult.storePath.to_string())));
402+
auto json = nlohmann::json::parse(store->getFSAccessor(downloadResult.storePath)->readFile(CanonPath::root));
404403

405404
return RefInfo{
406405
.rev = Hash::parseAny(std::string{json["sha"]}, HashAlgorithm::SHA1),
@@ -473,9 +472,8 @@ struct GitLabInputScheme : GitArchiveInputScheme
473472

474473
Headers headers = makeHeadersWithAuthTokens(*input.settings, host, input);
475474

476-
auto accessor = store->getFSAccessor();
477475
auto downloadResult = downloadFile(store, *input.settings, url, "source", headers);
478-
auto json = nlohmann::json::parse(accessor->readFile(CanonPath(downloadResult.storePath.to_string())));
476+
auto json = nlohmann::json::parse(store->getFSAccessor(downloadResult.storePath)->readFile(CanonPath::root));
479477

480478
if (json.is_array() && json.size() >= 1 && json[0]["id"] != nullptr) {
481479
return RefInfo{.rev = Hash::parseAny(std::string(json[0]["id"]), HashAlgorithm::SHA1)};

src/libfetchers/include/nix/fetchers/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ headers = files(
1111
'git-utils.hh',
1212
'input-cache.hh',
1313
'registry.hh',
14-
'store-path-accessor.hh',
1514
'tarball.hh',
1615
)

src/libfetchers/include/nix/fetchers/store-path-accessor.hh

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/libfetchers/mercurial.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "nix/util/tarfile.hh"
77
#include "nix/store/store-api.hh"
88
#include "nix/util/url-parts.hh"
9-
#include "nix/fetchers/store-path-accessor.hh"
109
#include "nix/fetchers/fetch-settings.hh"
1110

1211
#include <sys/time.h>
@@ -331,7 +330,8 @@ struct MercurialInputScheme : InputScheme
331330

332331
auto storePath = fetchToStore(store, input);
333332

334-
auto accessor = makeStorePathAccessor(store, storePath);
333+
// We just added it, it should be there.
334+
auto accessor = ref{store->getFSAccessor(storePath)};
335335

336336
accessor->setPathDisplay("«" + input.to_string() + "»");
337337

src/libfetchers/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ sources = files(
5050
'mercurial.cc',
5151
'path.cc',
5252
'registry.cc',
53-
'store-path-accessor.cc',
5453
'tarball.cc',
5554
)
5655

src/libfetchers/path.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "nix/fetchers/fetchers.hh"
22
#include "nix/store/store-api.hh"
33
#include "nix/util/archive.hh"
4-
#include "nix/fetchers/store-path-accessor.hh"
54
#include "nix/fetchers/cache.hh"
65
#include "nix/fetchers/fetch-to-store.hh"
76
#include "nix/fetchers/fetch-settings.hh"
@@ -153,7 +152,7 @@ struct PathInputScheme : InputScheme
153152
if (!input.getLastModified())
154153
input.attrs.insert_or_assign("lastModified", uint64_t(mtime));
155154

156-
return {makeStorePathAccessor(store, *storePath), std::move(input)};
155+
return {ref{store->getFSAccessor(*storePath)}, std::move(input)};
157156
}
158157

159158
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override

src/libfetchers/store-path-accessor.cc

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/libfetchers/tarball.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "nix/util/archive.hh"
77
#include "nix/util/tarfile.hh"
88
#include "nix/util/types.hh"
9-
#include "nix/fetchers/store-path-accessor.hh"
109
#include "nix/store/store-api.hh"
1110
#include "nix/fetchers/git-utils.hh"
1211
#include "nix/fetchers/fetch-settings.hh"
@@ -354,7 +353,7 @@ struct FileInputScheme : CurlInputScheme
354353
auto narHash = store->queryPathInfo(file.storePath)->narHash;
355354
input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
356355

357-
auto accessor = makeStorePathAccessor(store, file.storePath);
356+
auto accessor = ref{store->getFSAccessor(file.storePath)};
358357

359358
accessor->setPathDisplay("«" + input.to_string() + "»");
360359

src/libstore/binary-cache-store.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,21 @@ void BinaryCacheStore::registerDrvOutput(const Realisation & info)
539539
upsertFile(filePath, static_cast<nlohmann::json>(info).dump(), "application/json");
540540
}
541541

542-
ref<SourceAccessor> BinaryCacheStore::getFSAccessor(bool requireValidPath)
542+
ref<RemoteFSAccessor> BinaryCacheStore::getRemoteFSAccessor(bool requireValidPath)
543543
{
544544
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()), requireValidPath, config.localNarCache);
545545
}
546546

547+
ref<SourceAccessor> BinaryCacheStore::getFSAccessor(bool requireValidPath)
548+
{
549+
return getRemoteFSAccessor(requireValidPath);
550+
}
551+
552+
std::shared_ptr<SourceAccessor> BinaryCacheStore::getFSAccessor(const StorePath & storePath, bool requireValidPath)
553+
{
554+
return getRemoteFSAccessor(requireValidPath)->accessObject(storePath);
555+
}
556+
547557
void BinaryCacheStore::addSignatures(const StorePath & storePath, const StringSet & sigs)
548558
{
549559
/* Note: this is inherently racy since there is no locking on

0 commit comments

Comments
 (0)