forked from lix-project/lix
Add makeFixedOutputPathFromCA function
This puts what we are already doing into a shared method. It just needs a path name and a ca and produces a store path.
This commit is contained in:
parent
006f1252d2
commit
b2cb288cdd
|
@ -862,15 +862,10 @@ void LocalStore::querySubstitutablePathInfos(const StorePathSet & paths,
|
||||||
for (auto & path : paths) {
|
for (auto & path : paths) {
|
||||||
auto subPath(path.clone());
|
auto subPath(path.clone());
|
||||||
|
|
||||||
auto ca_ = pathsCA.find(printStorePath(path));
|
auto ca = pathsCA.find(printStorePath(path));
|
||||||
// recompute store path so that we can use a different store root
|
// recompute store path so that we can use a different store root
|
||||||
if (ca_ != pathsCA.end()) {
|
if (ca != pathsCA.end() && (hasPrefix(ca->second, "fixed:") || hasPrefix(ca->second, "text:"))) {
|
||||||
auto ca(ca_->second);
|
subPath = makeFixedOutputPathFromCA(path.name(), ca->second);
|
||||||
if (!hasPrefix(ca, "fixed:"))
|
|
||||||
continue;
|
|
||||||
FileIngestionMethod ingestionMethod { ca.compare(6, 2, "r:") == 0 };
|
|
||||||
Hash hash(std::string(ca, ingestionMethod == FileIngestionMethod::Recursive ? 8 : 6));
|
|
||||||
subPath = makeFixedOutputPath(ingestionMethod, hash, path.name());
|
|
||||||
if (subPath != path)
|
if (subPath != path)
|
||||||
debug("replaced path '%s' with '%s' for substituter '%s'", printStorePath(path), sub->printStorePath(subPath), sub->getUri());
|
debug("replaced path '%s' with '%s' for substituter '%s'", printStorePath(path), sub->printStorePath(subPath), sub->getUri());
|
||||||
} else if (sub->storeDir != storeDir) continue;
|
} else if (sub->storeDir != storeDir) continue;
|
||||||
|
|
|
@ -191,6 +191,19 @@ StorePath Store::makeFixedOutputPath(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StorePath Store::makeFixedOutputPathFromCA(std::string_view name, std::string ca,
|
||||||
|
const StorePathSet & references, bool hasSelfReference) const
|
||||||
|
{
|
||||||
|
if (hasPrefix(ca, "fixed:")) {
|
||||||
|
FileIngestionMethod ingestionMethod { ca.compare(6, 2, "r:") == 0 };
|
||||||
|
Hash hash(std::string(ca, ingestionMethod == FileIngestionMethod::Recursive ? 8 : 6));
|
||||||
|
return makeFixedOutputPath(ingestionMethod, hash, name, references, hasSelfReference);
|
||||||
|
} else if (hasPrefix(ca, "text:")) {
|
||||||
|
Hash hash(std::string(ca, 5));
|
||||||
|
return makeTextPath(name, hash, references);
|
||||||
|
} else
|
||||||
|
throw Error("'%s' is not a valid ca", ca);
|
||||||
|
}
|
||||||
|
|
||||||
StorePath Store::makeTextPath(std::string_view name, const Hash & hash,
|
StorePath Store::makeTextPath(std::string_view name, const Hash & hash,
|
||||||
const StorePathSet & references) const
|
const StorePathSet & references) const
|
||||||
|
@ -583,9 +596,7 @@ void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
|
||||||
// recompute store path on the chance dstStore does it differently
|
// recompute store path on the chance dstStore does it differently
|
||||||
if (info->isContentAddressed(*srcStore)) {
|
if (info->isContentAddressed(*srcStore)) {
|
||||||
auto info2 = make_ref<ValidPathInfo>(*info);
|
auto info2 = make_ref<ValidPathInfo>(*info);
|
||||||
FileIngestionMethod ingestionMethod { info->ca.compare(6, 2, "r:") == 0 };
|
info2->path = dstStore->makeFixedOutputPathFromCA(info->path.name(), info->ca);
|
||||||
Hash hash(std::string(info->ca, ingestionMethod == FileIngestionMethod::Recursive ? 8 : 6));
|
|
||||||
info2->path = dstStore->makeFixedOutputPath(ingestionMethod, hash, storePath.name());
|
|
||||||
info = info2;
|
info = info2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -656,11 +667,8 @@ void copyPaths(ref<Store> srcStore, ref<Store> dstStore, const StorePathSet & st
|
||||||
|
|
||||||
auto info = srcStore->queryPathInfo(storePath);
|
auto info = srcStore->queryPathInfo(storePath);
|
||||||
auto storePathForDst = storePath.clone();
|
auto storePathForDst = storePath.clone();
|
||||||
if (hasPrefix(info->ca, "fixed:"))
|
if (info->isContentAddressed(*srcStore)) {
|
||||||
{
|
storePathForDst = dstStore->makeFixedOutputPathFromCA(storePath.name(), info->ca);
|
||||||
FileIngestionMethod ingestionMethod { info->ca.compare(6, 2, "r:") == 0 };
|
|
||||||
Hash hash(std::string(info->ca, ingestionMethod == FileIngestionMethod::Recursive ? 8 : 6));
|
|
||||||
storePathForDst = dstStore->makeFixedOutputPath(ingestionMethod, hash, storePath.name());
|
|
||||||
if (storePathForDst != storePath)
|
if (storePathForDst != storePath)
|
||||||
debug("rewriting path '%s' to '%s' for substituter '%s'", srcStore->printStorePath(storePath), dstStore->printStorePath(storePathForDst), dstStore->getUri());
|
debug("rewriting path '%s' to '%s' for substituter '%s'", srcStore->printStorePath(storePath), dstStore->printStorePath(storePathForDst), dstStore->getUri());
|
||||||
}
|
}
|
||||||
|
@ -684,11 +692,8 @@ void copyPaths(ref<Store> srcStore, ref<Store> dstStore, const StorePathSet & st
|
||||||
auto info = srcStore->queryPathInfo(storePath);
|
auto info = srcStore->queryPathInfo(storePath);
|
||||||
|
|
||||||
auto storePathForDst = storePath.clone();
|
auto storePathForDst = storePath.clone();
|
||||||
if (hasPrefix(info->ca, "fixed:"))
|
if (info->isContentAddressed(*srcStore)) {
|
||||||
{
|
storePathForDst = dstStore->makeFixedOutputPathFromCA(storePath.name(), info->ca);
|
||||||
FileIngestionMethod ingestionMethod { info->ca.compare(6, 2, "r:") == 0 };
|
|
||||||
Hash hash(std::string(info->ca, ingestionMethod == FileIngestionMethod::Recursive ? 8 : 6));
|
|
||||||
storePathForDst = dstStore->makeFixedOutputPath(ingestionMethod, hash, storePath.name());
|
|
||||||
if (storePathForDst != storePath)
|
if (storePathForDst != storePath)
|
||||||
debug("rewriting path '%s' to '%s' for substituter '%s'", srcStore->printStorePath(storePath), dstStore->printStorePath(storePathForDst), dstStore->getUri());
|
debug("rewriting path '%s' to '%s' for substituter '%s'", srcStore->printStorePath(storePath), dstStore->printStorePath(storePathForDst), dstStore->getUri());
|
||||||
}
|
}
|
||||||
|
|
|
@ -352,7 +352,11 @@ public:
|
||||||
bool hasSelfReference = false) const;
|
bool hasSelfReference = false) const;
|
||||||
|
|
||||||
StorePath makeTextPath(std::string_view name, const Hash & hash,
|
StorePath makeTextPath(std::string_view name, const Hash & hash,
|
||||||
const StorePathSet & references) const;
|
const StorePathSet & references = {}) const;
|
||||||
|
|
||||||
|
StorePath makeFixedOutputPathFromCA(std::string_view name, std::string ca,
|
||||||
|
const StorePathSet & references = {},
|
||||||
|
bool hasSelfReference = false) const;
|
||||||
|
|
||||||
/* This is the preparatory part of addToStore(); it computes the
|
/* This is the preparatory part of addToStore(); it computes the
|
||||||
store path to which srcPath is to be copied. Returns the store
|
store path to which srcPath is to be copied. Returns the store
|
||||||
|
|
Loading…
Reference in a new issue