Skip to content

Commit

Permalink
Merge pull request #40 from obsidiansystems/ipfs-store-path-or-ca
Browse files Browse the repository at this point in the history
Prepare for NixOS#137
  • Loading branch information
Ericson2314 committed Jun 30, 2020
2 parents 704e500 + 16e3e9e commit 80ad1d1
Show file tree
Hide file tree
Showing 44 changed files with 724 additions and 466 deletions.
12 changes: 10 additions & 2 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,11 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
std::optional<HashType> ht = parseHashTypeOpt(outputHashAlgo);
Hash h = newHashAllowEmpty(*outputHash, ht);

auto outPath = state.store->makeFixedOutputPath(ingestionMethod, h, drvName);
auto outPath = state.store->makeFixedOutputPath(drvName, FixedOutputInfo {
ingestionMethod,
h,
{},
});
if (!jsonObject) drv.env["out"] = state.store->printStorePath(outPath);
drv.outputs.insert_or_assign("out", DerivationOutput {
.path = std::move(outPath),
Expand Down Expand Up @@ -1153,7 +1157,11 @@ static void addPath(EvalState & state, const Pos & pos, const string & name, con

std::optional<StorePath> expectedStorePath;
if (expectedHash)
expectedStorePath = state.store->makeFixedOutputPath(method, expectedHash, name);
expectedStorePath = state.store->makeFixedOutputPath(name, FixedOutputInfo {
method,
expectedHash,
{},
});
Path dstPath;
if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) {
dstPath = state.store->printStorePath(settings.readOnlyMode
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/value-to-xml.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ namespace nix {

void printValueAsXML(EvalState & state, bool strict, bool location,
Value & v, std::ostream & out, PathSet & context);

}
14 changes: 9 additions & 5 deletions src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,17 @@ std::pair<Tree, std::shared_ptr<const Input>> Input::fetchTree(ref<Store> store)
std::optional<StorePath> trySubstitute(ref<Store> store, FileIngestionMethod ingestionMethod,
Hash hash, std::string_view name)
{
auto substitutablePath = store->makeFixedOutputPath(ingestionMethod, hash, name);
auto ca = FullContentAddress {
.name = std::string { name },
.info = FixedOutputInfo {
ingestionMethod,
hash,
{}
},
};
auto substitutablePath = store->makeFixedOutputPathFromCA(ca);

try {
auto ca = FixedOutputHash {
.method = ingestionMethod,
.hash = hash
};
store->ensurePath(substitutablePath, ca);

debug("using substituted path '%s'", store->printStorePath(substitutablePath));
Expand Down
12 changes: 8 additions & 4 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ struct GitInput : Input
warn("Nix's computed git tree hash will be different when submodules are converted to regular directories");
}

std::optional<ContentAddress> ca;
std::optional<FullContentAddress> ca;
if (treeHash)
ca = FixedOutputHash {
.method = ingestionMethod,
.hash = *treeHash,
ca = FullContentAddress {
.name = name,
.info = FixedOutputInfo {
ingestionMethod,
*treeHash,
{},
}
};

// try to substitute
Expand Down
16 changes: 11 additions & 5 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ DownloadFileResult downloadFile(
StringSink sink;
dumpString(*res.data, sink);
auto hash = hashString(htSHA256, *res.data);
ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Flat, hash, name));
ValidPathInfo info {
*store,
FullContentAddress {
.name = name,
.info = FixedOutputInfo {
FileIngestionMethod::Flat,
hash,
{},
},
},
};
info.narHash = hashString(htSHA256, *sink.s);
info.narSize = sink.s->size();
info.ca = FixedOutputHash {
.method = FileIngestionMethod::Flat,
.hash = hash,
};
auto source = StringSource { *sink.s };
store->addToStore(info, source, NoRepair, NoCheckSigs);
storePath = std::move(info.path);
Expand Down
6 changes: 5 additions & 1 deletion src/libfetchers/tree-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ namespace nix::fetchers {
StorePath TreeInfo::computeStorePath(Store & store) const
{
assert(narHash);
return store.makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, "source");
return store.makeFixedOutputPath("source", FixedOutputInfo {
FileIngestionMethod::Recursive,
narHash,
{},
});
}

}
3 changes: 2 additions & 1 deletion src/libfetchers/tree-info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "path.hh"
#include "hash.hh"
#include "content-address.hh"

#include <nlohmann/json_fwd.hpp>

Expand All @@ -13,7 +14,7 @@ struct TreeInfo
{
Hash narHash;

std::optional<ContentAddress> ca;
std::optional<FullContentAddress> ca;

std::optional<uint64_t> revCount;
std::optional<time_t> lastModified;
Expand Down
15 changes: 9 additions & 6 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, Source & narSource
reads, but typically they'll already be cached. */
for (auto & ref : info.references)
try {
if (ref != info.path)
queryPathInfo(ref);
queryPathInfo(ref);
} catch (InvalidPath &) {
throw Error("cannot add '%s' to the binary cache because the reference '%s' is not valid",
printStorePath(info.path), printStorePath(ref));
Expand Down Expand Up @@ -263,15 +262,15 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, Source & narSource
stats.narInfoWrite++;
}

bool BinaryCacheStore::isValidPathUncached(const StorePath & storePath, std::optional<ContentAddress> ca)
bool BinaryCacheStore::isValidPathUncached(const StorePath & storePath, std::optional<FullContentAddress> ca)
{
// FIXME: this only checks whether a .narinfo with a matching hash
// part exists. So ‘f4kb...-foo’ matches ‘f4kb...-bar’, even
// though they shouldn't. Not easily fixed.
return fileExists(narInfoFileFor(storePath));
}

void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink, std::optional<ContentAddress> ca)
void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink, std::optional<FullContentAddress> ca)
{
auto info = queryPathInfo(storePath).cast<const NarInfo>();

Expand All @@ -298,7 +297,7 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink, std
}

void BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath,
Callback<std::shared_ptr<const ValidPathInfo>> callback, std::optional<ContentAddress> ca) noexcept
Callback<std::shared_ptr<const ValidPathInfo>> callback, std::optional<FullContentAddress> ca) noexcept
{
auto uri = getUri();
auto storePathS = printStorePath(storePath);
Expand Down Expand Up @@ -354,7 +353,11 @@ StorePath BinaryCacheStore::addToStore(const string & name, const Path & srcPath
throw Error("cannot add to binary cache store using the git file ingestion method");
}

ValidPathInfo info(makeFixedOutputPath(method, h, name));
ValidPathInfo info(makeFixedOutputPath(name, FixedOutputInfo {
method,
h,
{},
}));

auto source = StringSource { *sink.s };
addToStore(info, source, repair, CheckSigs, nullptr);
Expand Down
8 changes: 4 additions & 4 deletions src/libstore/binary-cache-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ private:

public:

bool isValidPathUncached(const StorePath & path, std::optional<ContentAddress> ca) override;
bool isValidPathUncached(const StorePath & path, std::optional<FullContentAddress> ca) override;

void queryPathInfoUncached(const StorePath & path,
Callback<std::shared_ptr<const ValidPathInfo>> callback, std::optional<ContentAddress> ca) noexcept override;
Callback<std::shared_ptr<const ValidPathInfo>> callback, std::optional<FullContentAddress> ca) noexcept override;

std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
{ unsupported("queryPathFromHashPart"); }
Expand All @@ -85,13 +85,13 @@ public:
StorePath addTextToStore(const string & name, const string & s,
const StorePathSet & references, RepairFlag repair) override;

void narFromPath(const StorePath & path, Sink & sink, std::optional<ContentAddress> ca) override;
void narFromPath(const StorePath & path, Sink & sink, std::optional<FullContentAddress> ca) override;

BuildResult buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
BuildMode buildMode) override
{ unsupported("buildDerivation"); }

void ensurePath(const StorePath & path, std::optional<ContentAddress> ca) override
void ensurePath(const StorePath & path, std::optional<FullContentAddress> ca) override
{ unsupported("ensurePath"); }

ref<FSAccessor> getFSAccessor() override;
Expand Down
Loading

0 comments on commit 80ad1d1

Please sign in to comment.