mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
Merge pull request #14333 from lovesegfault/upsert-size-hint
refactor(libstore): add sizeHint parameter to upsertFile()
This commit is contained in:
commit
1a9ba0d6fe
4 changed files with 25 additions and 7 deletions
|
|
@ -76,9 +76,10 @@ std::optional<std::string> BinaryCacheStore::getNixCacheInfo()
|
||||||
return getFile(cacheInfoFile);
|
return getFile(cacheInfoFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryCacheStore::upsertFile(const std::string & path, std::string && data, const std::string & mimeType)
|
void BinaryCacheStore::upsertFile(
|
||||||
|
const std::string & path, std::string && data, const std::string & mimeType, uint64_t sizeHint)
|
||||||
{
|
{
|
||||||
upsertFile(path, std::make_shared<std::stringstream>(std::move(data)), mimeType);
|
upsertFile(path, std::make_shared<std::stringstream>(std::move(data)), mimeType, sizeHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryCacheStore::getFile(const std::string & path, Callback<std::optional<std::string>> callback) noexcept
|
void BinaryCacheStore::getFile(const std::string & path, Callback<std::optional<std::string>> callback) noexcept
|
||||||
|
|
@ -274,7 +275,8 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
|
||||||
upsertFile(
|
upsertFile(
|
||||||
narInfo->url,
|
narInfo->url,
|
||||||
std::make_shared<std::fstream>(fnTemp, std::ios_base::in | std::ios_base::binary),
|
std::make_shared<std::fstream>(fnTemp, std::ios_base::in | std::ios_base::binary),
|
||||||
"application/x-nix-nar");
|
"application/x-nix-nar",
|
||||||
|
narInfo->fileSize);
|
||||||
} else
|
} else
|
||||||
stats.narWriteAverted++;
|
stats.narWriteAverted++;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,8 @@ protected:
|
||||||
void upsertFile(
|
void upsertFile(
|
||||||
const std::string & path,
|
const std::string & path,
|
||||||
std::shared_ptr<std::basic_iostream<char>> istream,
|
std::shared_ptr<std::basic_iostream<char>> istream,
|
||||||
const std::string & mimeType) override
|
const std::string & mimeType,
|
||||||
|
uint64_t sizeHint) override
|
||||||
{
|
{
|
||||||
auto req = makeRequest(path);
|
auto req = makeRequest(path);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,13 +101,27 @@ public:
|
||||||
virtual bool fileExists(const std::string & path) = 0;
|
virtual bool fileExists(const std::string & path) = 0;
|
||||||
|
|
||||||
virtual void upsertFile(
|
virtual void upsertFile(
|
||||||
const std::string & path, std::shared_ptr<std::basic_iostream<char>> istream, const std::string & mimeType) = 0;
|
const std::string & path,
|
||||||
|
std::shared_ptr<std::basic_iostream<char>> istream,
|
||||||
|
const std::string & mimeType,
|
||||||
|
uint64_t sizeHint) = 0;
|
||||||
|
|
||||||
void upsertFile(
|
void upsertFile(
|
||||||
const std::string & path,
|
const std::string & path,
|
||||||
// FIXME: use std::string_view
|
// FIXME: use std::string_view
|
||||||
std::string && data,
|
std::string && data,
|
||||||
const std::string & mimeType);
|
const std::string & mimeType,
|
||||||
|
uint64_t sizeHint);
|
||||||
|
|
||||||
|
void upsertFile(
|
||||||
|
const std::string & path,
|
||||||
|
// FIXME: use std::string_view
|
||||||
|
std::string && data,
|
||||||
|
const std::string & mimeType)
|
||||||
|
{
|
||||||
|
auto size = data.size();
|
||||||
|
upsertFile(path, std::move(data), mimeType, size);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dump the contents of the specified file to a sink.
|
* Dump the contents of the specified file to a sink.
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,8 @@ protected:
|
||||||
void upsertFile(
|
void upsertFile(
|
||||||
const std::string & path,
|
const std::string & path,
|
||||||
std::shared_ptr<std::basic_iostream<char>> istream,
|
std::shared_ptr<std::basic_iostream<char>> istream,
|
||||||
const std::string & mimeType) override
|
const std::string & mimeType,
|
||||||
|
uint64_t sizeHint) override
|
||||||
{
|
{
|
||||||
auto path2 = config->binaryCacheDir + "/" + path;
|
auto path2 = config->binaryCacheDir + "/" + path;
|
||||||
static std::atomic<int> counter{0};
|
static std::atomic<int> counter{0};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue