Skip to content

Commit

Permalink
Merge remote-tracking branch 'obsidian/validPathInfo-ca-proper-dataty…
Browse files Browse the repository at this point in the history
…pe' into ipfs-develop
  • Loading branch information
Ericson2314 committed Jun 19, 2020
2 parents 568d6da + e288c09 commit 8e6f79b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ DownloadFileResult downloadFile(
info.narHash = hashString(htSHA256, *sink.s);
info.narSize = sink.s->size();
info.ca = FixedOutputHash {
FileIngestionMethod::Flat,
hash,
.method = FileIngestionMethod::Flat,
.hash = hash,
};
auto source = StringSource { *sink.s };
store->addToStore(info, source, NoRepair, NoCheckSigs);
Expand Down
5 changes: 4 additions & 1 deletion src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3764,7 +3764,10 @@ void DerivationGoal::registerOutputs()
else
assert(worker.store.parseStorePath(path) == dest);

ca = FixedOutputHash { i.second.hash->method, h2 };
ca = FixedOutputHash {
.method = i.second.hash->method,
.hash = h2,
};
}

/* Get rid of all weird permissions. This also checks that
Expand Down
15 changes: 12 additions & 3 deletions src/libstore/content-address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,22 @@ ContentAddress parseContentAddress(std::string_view rawCa) {
auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos);
if (methodAndHash.substr(0, 2) == "r:") {
std::string_view hashRaw = methodAndHash.substr(2, string::npos);
return FixedOutputHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) };
return FixedOutputHash {
.method = FileIngestionMethod::Recursive,
.hash = Hash(string(hashRaw)),
};
} else if (methodAndHash.substr(0, 4) == "git:") {
std::string_view hashRaw = methodAndHash.substr(4, string::npos);
return FixedOutputHash { FileIngestionMethod::Git, Hash(string(hashRaw)) };
return FixedOutputHash {
.method = FileIngestionMethod::Git,
.hash = Hash(string(hashRaw)),
};
} else {
std::string_view hashRaw = methodAndHash;
return FixedOutputHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) };
return FixedOutputHash {
.method = FileIngestionMethod::Flat,
.hash = Hash(string(hashRaw)),
};
}
} else {
throw Error("parseContentAddress: format not recognized; has to be text or fixed");
Expand Down
10 changes: 0 additions & 10 deletions src/libstore/content-address.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,12 @@ enum struct FileIngestionMethod : uint8_t {

struct TextHash {
Hash hash;
TextHash(const TextHash &) = default;
TextHash(TextHash &&) = default;
TextHash & operator = (const TextHash &) = default;
};

/// Pair of a hash, and how the file system was ingested
struct FixedOutputHash {
FileIngestionMethod method;
Hash hash;
FixedOutputHash(FileIngestionMethod method, Hash hash)
: method(std::move(method))
, hash(std::move(hash))
{ }
FixedOutputHash(const FixedOutputHash &) = default;
FixedOutputHash(FixedOutputHash &&) = default;
FixedOutputHash & operator = (const FixedOutputHash &) = default;
std::string printMethodAlgo() const;
};

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam
ValidPathInfo info(dstPath);
info.narHash = hash.first;
info.narSize = hash.second;
info.ca = FixedOutputHash { method, h };
info.ca = FixedOutputHash { .method = method, .hash = h };
registerValidPath(info);
}

Expand Down
5 changes: 4 additions & 1 deletion src/nix/add-to-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ struct CmdAddToStore : MixDryRun, StoreCommand
ValidPathInfo info(store->makeFixedOutputPath(ingestionMethod, hash, *namePart));
info.narHash = narHash;
info.narSize = sink.s->size();
info.ca = FixedOutputHash { ingestionMethod, hash };
info.ca = std::optional { FixedOutputHash {
.method = ingestionMethod,
.hash = info.narHash,
} };

if (!dryRun) {
auto addedPath = store->addToStore(*namePart, path, ingestionMethod, git ? htSHA1 : htSHA256);
Expand Down
4 changes: 2 additions & 2 deletions src/nix/make-content-addressable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
info.narHash = narHash;
info.narSize = sink.s->size();
info.ca = FixedOutputHash {
FileIngestionMethod::Recursive,
info.narHash,
.method = FileIngestionMethod::Recursive,
.hash = info.narHash,
};

if (!json)
Expand Down

0 comments on commit 8e6f79b

Please sign in to comment.