mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
refactor(libstore): add sizeHint parameter to upsertFile()
Add a sizeHint parameter to BinaryCacheStore::upsertFile() to enable size-based upload decisions in implementations. This lays the groundwork for reintroducing S3 multipart upload support.
This commit is contained in:
parent
115dea10b2
commit
6b7223b6b7
4 changed files with 25 additions and 7 deletions
|
|
@ -76,9 +76,10 @@ std::optional<std::string> BinaryCacheStore::getNixCacheInfo()
|
|||
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
|
||||
|
|
@ -274,7 +275,8 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
|
|||
upsertFile(
|
||||
narInfo->url,
|
||||
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
|
||||
stats.narWriteAverted++;
|
||||
|
||||
|
|
|
|||
|
|
@ -143,7 +143,8 @@ protected:
|
|||
void upsertFile(
|
||||
const std::string & path,
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -101,13 +101,27 @@ public:
|
|||
virtual bool fileExists(const std::string & path) = 0;
|
||||
|
||||
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(
|
||||
const std::string & path,
|
||||
// FIXME: use std::string_view
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ protected:
|
|||
void upsertFile(
|
||||
const std::string & path,
|
||||
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;
|
||||
static std::atomic<int> counter{0};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue