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
4 changes: 2 additions & 2 deletions src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "nix/util/source-path.hh"
#include "nix/fetchers/fetch-to-store.hh"
#include "nix/util/json-utils.hh"
#include "nix/fetchers/store-path-accessor.hh"
#include "nix/fetchers/fetch-settings.hh"

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

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

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

accessor->fingerprint = getFingerprint(store);

Expand Down
6 changes: 2 additions & 4 deletions src/libfetchers/github.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,8 @@ struct GitHubInputScheme : GitArchiveInputScheme

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

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

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

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

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

if (json.is_array() && json.size() >= 1 && json[0]["id"] != nullptr) {
return RefInfo{.rev = Hash::parseAny(std::string(json[0]["id"]), HashAlgorithm::SHA1)};
Expand Down
1 change: 0 additions & 1 deletion src/libfetchers/include/nix/fetchers/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ headers = files(
'git-utils.hh',
'input-cache.hh',
'registry.hh',
'store-path-accessor.hh',
'tarball.hh',
)
14 changes: 0 additions & 14 deletions src/libfetchers/include/nix/fetchers/store-path-accessor.hh

This file was deleted.

4 changes: 2 additions & 2 deletions src/libfetchers/mercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "nix/util/tarfile.hh"
#include "nix/store/store-api.hh"
#include "nix/util/url-parts.hh"
#include "nix/fetchers/store-path-accessor.hh"
#include "nix/fetchers/fetch-settings.hh"

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

auto storePath = fetchToStore(store, input);

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

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

Expand Down
1 change: 0 additions & 1 deletion src/libfetchers/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ sources = files(
'mercurial.cc',
'path.cc',
'registry.cc',
'store-path-accessor.cc',
'tarball.cc',
)

Expand Down
3 changes: 1 addition & 2 deletions src/libfetchers/path.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "nix/fetchers/fetchers.hh"
#include "nix/store/store-api.hh"
#include "nix/util/archive.hh"
#include "nix/fetchers/store-path-accessor.hh"
#include "nix/fetchers/cache.hh"
#include "nix/fetchers/fetch-to-store.hh"
#include "nix/fetchers/fetch-settings.hh"
Expand Down Expand Up @@ -153,7 +152,7 @@ struct PathInputScheme : InputScheme
if (!input.getLastModified())
input.attrs.insert_or_assign("lastModified", uint64_t(mtime));

return {makeStorePathAccessor(store, *storePath), std::move(input)};
return {ref{store->getFSAccessor(*storePath)}, std::move(input)};
}

std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
Expand Down
11 changes: 0 additions & 11 deletions src/libfetchers/store-path-accessor.cc

This file was deleted.

3 changes: 1 addition & 2 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "nix/util/archive.hh"
#include "nix/util/tarfile.hh"
#include "nix/util/types.hh"
#include "nix/fetchers/store-path-accessor.hh"
#include "nix/store/store-api.hh"
#include "nix/fetchers/git-utils.hh"
#include "nix/fetchers/fetch-settings.hh"
Expand Down Expand Up @@ -354,7 +353,7 @@ struct FileInputScheme : CurlInputScheme
auto narHash = store->queryPathInfo(file.storePath)->narHash;
input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));

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

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

Expand Down
12 changes: 11 additions & 1 deletion src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,21 @@ void BinaryCacheStore::registerDrvOutput(const Realisation & info)
upsertFile(filePath, static_cast<nlohmann::json>(info).dump(), "application/json");
}

ref<SourceAccessor> BinaryCacheStore::getFSAccessor(bool requireValidPath)
ref<RemoteFSAccessor> BinaryCacheStore::getRemoteFSAccessor(bool requireValidPath)
{
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()), requireValidPath, config.localNarCache);
}

ref<SourceAccessor> BinaryCacheStore::getFSAccessor(bool requireValidPath)
{
return getRemoteFSAccessor(requireValidPath);
}

std::shared_ptr<SourceAccessor> BinaryCacheStore::getFSAccessor(const StorePath & storePath, bool requireValidPath)
{
return getRemoteFSAccessor(requireValidPath)->accessObject(storePath);
}

void BinaryCacheStore::addSignatures(const StorePath & storePath, const StringSet & sigs)
{
/* Note: this is inherently racy since there is no locking on
Expand Down
9 changes: 8 additions & 1 deletion src/libstore/dummy-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,14 @@ struct DummyStore : virtual Store
callback(nullptr);
}

virtual ref<SourceAccessor> getFSAccessor(bool requireValidPath) override
std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath) override
{
std::shared_ptr<SourceAccessor> res;
contents.cvisit(path, [&](const auto & kv) { res = kv.second.contents.get_ptr(); });
return res;
}

ref<SourceAccessor> getFSAccessor(bool requireValidPath) override
{
return wholeStoreView;
}
Expand Down
8 changes: 8 additions & 0 deletions src/libstore/include/nix/store/binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace nix {

struct NarInfo;
class RemoteFSAccessor;

struct BinaryCacheStoreConfig : virtual StoreConfig
{
Expand Down Expand Up @@ -136,6 +137,11 @@ private:
CheckSigsFlag checkSigs,
std::function<ValidPathInfo(HashResult)> mkInfo);

/**
* Same as `getFSAccessor`, but with a more preceise return type.
*/
ref<RemoteFSAccessor> getRemoteFSAccessor(bool requireValidPath = true);

public:

bool isValidPathUncached(const StorePath & path) override;
Expand Down Expand Up @@ -175,6 +181,8 @@ public:

ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override;

std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath &, bool requireValidPath = true) override;

void addSignatures(const StorePath & storePath, const StringSet & sigs) override;

std::optional<std::string> getBuildLogExact(const StorePath & path) override;
Expand Down
7 changes: 6 additions & 1 deletion src/libstore/include/nix/store/legacy-ssh-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ public:
unsupported("ensurePath");
}

virtual ref<SourceAccessor> getFSAccessor(bool requireValidPath) override
ref<SourceAccessor> getFSAccessor(bool requireValidPath) override
{
unsupported("getFSAccessor");
}

std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath) override
{
unsupported("getFSAccessor");
}
Expand Down
1 change: 1 addition & 0 deletions src/libstore/include/nix/store/local-fs-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct LocalFSStore : virtual Store, virtual GcStore, virtual LogStore

void narFromPath(const StorePath & path, Sink & sink) override;
ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override;
std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath = true) override;

/**
* Creates symlink from the `gcRoot` to the `storePath` and
Expand Down
5 changes: 5 additions & 0 deletions src/libstore/include/nix/store/remote-fs-accessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class RemoteFSAccessor : public SourceAccessor

public:

/**
* @return nullptr if the store does not contain any object at that path.
*/
std::shared_ptr<SourceAccessor> accessObject(const StorePath & path);

RemoteFSAccessor(
ref<Store> store, bool requireValidPath = true, const /* FIXME: use std::optional */ Path & cacheDir = "");

Expand Down
9 changes: 9 additions & 0 deletions src/libstore/include/nix/store/remote-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct FdSink;
struct FdSource;
template<typename T>
class Pool;
class RemoteFSAccessor;

struct RemoteStoreConfig : virtual StoreConfig
{
Expand Down Expand Up @@ -176,10 +177,18 @@ protected:

virtual ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) override;

virtual std::shared_ptr<SourceAccessor>
getFSAccessor(const StorePath & path, bool requireValidPath = true) override;

virtual void narFromPath(const StorePath & path, Sink & sink) override;

private:

/**
* Same as the default implemenation of `RemoteStore::getFSAccessor`, but with a more preceise return type.
*/
ref<RemoteFSAccessor> getRemoteFSAccessor(bool requireValidPath = true);

std::atomic_bool failed{false};

void copyDrvsFromEvalStore(const std::vector<DerivedPath> & paths, std::shared_ptr<Store> evalStore);
Expand Down
12 changes: 11 additions & 1 deletion src/libstore/include/nix/store/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,20 @@ public:
};

/**
* @return An object to access files in the Nix store.
* @return An object to access files in the Nix store, across all
* store objects.
*/
virtual ref<SourceAccessor> getFSAccessor(bool requireValidPath = true) = 0;

/**
* @return An object to access files for a specific store object in
* the Nix store.
*
* @return nullptr if the store doesn't contain an object at the
* givine path.
*/
virtual std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath = true) = 0;

/**
* Repair the contents of the given path by redownloading it using
* a substituter (if available).
Expand Down
5 changes: 5 additions & 0 deletions src/libstore/include/nix/store/uds-remote-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ struct UDSRemoteStore : virtual IndirectRootStore, virtual RemoteStore
return LocalFSStore::getFSAccessor(requireValidPath);
}

std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath = true) override
{
return LocalFSStore::getFSAccessor(path, requireValidPath);
}

void narFromPath(const StorePath & path, Sink & sink) override
{
LocalFSStore::narFromPath(path, sink);
Expand Down
17 changes: 17 additions & 0 deletions src/libstore/local-fs-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ ref<SourceAccessor> LocalFSStore::getFSAccessor(bool requireValidPath)
ref<LocalFSStore>(std::dynamic_pointer_cast<LocalFSStore>(shared_from_this())), requireValidPath);
}

std::shared_ptr<SourceAccessor> LocalFSStore::getFSAccessor(const StorePath & path, bool requireValidPath)
{
auto absPath = std::filesystem::path{config.realStoreDir.get()} / path.to_string();
if (requireValidPath) {
/* Only return non-null if the store object is a fully-valid
member of the store. */
if (!isValidPath(path))
return nullptr;
} else {
/* Return non-null as long as the some file system data exists,
even if the store object is not fully registered. */
if (!pathExists(absPath))
return nullptr;
}
return std::make_shared<PosixSourceAccessor>(std::move(absPath));
}

void LocalFSStore::narFromPath(const StorePath & path, Sink & sink)
{
if (!isValidPath(path))
Expand Down
16 changes: 9 additions & 7 deletions src/libstore/remote-fs-accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ ref<SourceAccessor> RemoteFSAccessor::addToCache(std::string_view hashPart, std:

std::pair<ref<SourceAccessor>, CanonPath> RemoteFSAccessor::fetch(const CanonPath & path)
{
auto [storePath, restPath_] = store->toStorePath(store->storeDir + path.abs());
auto restPath = CanonPath(restPath_);

auto [storePath, restPath] = store->toStorePath(store->storeDir + path.abs());
if (requireValidPath && !store->isValidPath(storePath))
throw InvalidPath("path '%1%' is not a valid store path", store->printStorePath(storePath));
return {ref{accessObject(storePath)}, CanonPath{restPath}};
}

std::shared_ptr<SourceAccessor> RemoteFSAccessor::accessObject(const StorePath & storePath)
{
auto i = nars.find(std::string(storePath.hashPart()));
if (i != nars.end())
return {i->second, restPath};
return i->second;

std::string listing;
Path cacheFile;
Expand Down Expand Up @@ -90,22 +92,22 @@ std::pair<ref<SourceAccessor>, CanonPath> RemoteFSAccessor::fetch(const CanonPat
});

nars.emplace(storePath.hashPart(), narAccessor);
return {narAccessor, restPath};
return narAccessor;

} catch (SystemError &) {
}

try {
auto narAccessor = makeNarAccessor(nix::readFile(cacheFile));
nars.emplace(storePath.hashPart(), narAccessor);
return {narAccessor, restPath};
return narAccessor;
} catch (SystemError &) {
}
}

StringSink sink;
store->narFromPath(storePath, sink);
return {addToCache(storePath.hashPart(), std::move(sink.s)), restPath};
return addToCache(storePath.hashPart(), std::move(sink.s));
}

std::optional<SourceAccessor::Stat> RemoteFSAccessor::maybeLstat(const CanonPath & path)
Expand Down
12 changes: 11 additions & 1 deletion src/libstore/remote-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,19 @@ void RemoteStore::narFromPath(const StorePath & path, Sink & sink)
conn->narFromPath(*this, &conn.daemonException, path, [&](Source & source) { copyNAR(conn->from, sink); });
}

ref<RemoteFSAccessor> RemoteStore::getRemoteFSAccessor(bool requireValidPath)
{
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()), requireValidPath);
}

ref<SourceAccessor> RemoteStore::getFSAccessor(bool requireValidPath)
{
return make_ref<RemoteFSAccessor>(ref<Store>(shared_from_this()));
return getRemoteFSAccessor(requireValidPath);
}

std::shared_ptr<SourceAccessor> RemoteStore::getFSAccessor(const StorePath & path, bool requireValidPath)
{
return getRemoteFSAccessor(requireValidPath)->accessObject(path);
}

void RemoteStore::ConnectionHandle::withFramedSink(std::function<void(Sink & sink)> fun)
Expand Down
Loading
Loading