forked from lix-project/lix
Make setDefault() typed
This commit is contained in:
parent
8fdb1d057a
commit
d8c10028d9
|
@ -52,9 +52,9 @@ void BinaryCacheStore::init()
|
||||||
throw Error("binary cache '%s' is for Nix stores with prefix '%s', not '%s'",
|
throw Error("binary cache '%s' is for Nix stores with prefix '%s', not '%s'",
|
||||||
getUri(), value, storeDir);
|
getUri(), value, storeDir);
|
||||||
} else if (name == "WantMassQuery") {
|
} else if (name == "WantMassQuery") {
|
||||||
wantMassQuery.setDefault(value == "1" ? "true" : "false");
|
wantMassQuery.setDefault(value == "1");
|
||||||
} else if (name == "Priority") {
|
} else if (name == "Priority") {
|
||||||
priority.setDefault(fmt("%d", std::stoi(value)));
|
priority.setDefault(std::stoi(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,8 @@ public:
|
||||||
{
|
{
|
||||||
// FIXME: do this lazily?
|
// FIXME: do this lazily?
|
||||||
if (auto cacheInfo = diskCache->cacheExists(cacheUri)) {
|
if (auto cacheInfo = diskCache->cacheExists(cacheUri)) {
|
||||||
wantMassQuery.setDefault(cacheInfo->wantMassQuery ? "true" : "false");
|
wantMassQuery.setDefault(cacheInfo->wantMassQuery);
|
||||||
priority.setDefault(fmt("%d", cacheInfo->priority));
|
priority.setDefault(cacheInfo->priority);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
BinaryCacheStore::init();
|
BinaryCacheStore::init();
|
||||||
|
|
|
@ -232,8 +232,8 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStoreConfig, public virtual
|
||||||
void init() override
|
void init() override
|
||||||
{
|
{
|
||||||
if (auto cacheInfo = diskCache->cacheExists(getUri())) {
|
if (auto cacheInfo = diskCache->cacheExists(getUri())) {
|
||||||
wantMassQuery.setDefault(cacheInfo->wantMassQuery ? "true" : "false");
|
wantMassQuery.setDefault(cacheInfo->wantMassQuery);
|
||||||
priority.setDefault(fmt("%d", cacheInfo->priority));
|
priority.setDefault(cacheInfo->priority);
|
||||||
} else {
|
} else {
|
||||||
BinaryCacheStore::init();
|
BinaryCacheStore::init();
|
||||||
diskCache->createCache(getUri(), storeDir, wantMassQuery, priority);
|
diskCache->createCache(getUri(), storeDir, wantMassQuery, priority);
|
||||||
|
|
|
@ -177,11 +177,6 @@ AbstractSetting::AbstractSetting(
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractSetting::setDefault(const std::string & str)
|
|
||||||
{
|
|
||||||
if (!overridden) set(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
nlohmann::json AbstractSetting::toJSON()
|
nlohmann::json AbstractSetting::toJSON()
|
||||||
{
|
{
|
||||||
return nlohmann::json(toJSONObject());
|
return nlohmann::json(toJSONObject());
|
||||||
|
|
|
@ -194,8 +194,6 @@ public:
|
||||||
|
|
||||||
bool overridden = false;
|
bool overridden = false;
|
||||||
|
|
||||||
void setDefault(const std::string & str);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
AbstractSetting(
|
AbstractSetting(
|
||||||
|
@ -253,6 +251,7 @@ public:
|
||||||
bool operator !=(const T & v2) const { return value != v2; }
|
bool operator !=(const T & v2) const { return value != v2; }
|
||||||
void operator =(const T & v) { assign(v); }
|
void operator =(const T & v) { assign(v); }
|
||||||
virtual void assign(const T & v) { value = v; }
|
virtual void assign(const T & v) { value = v; }
|
||||||
|
void setDefault(const T & v) { if (!overridden) value = v; }
|
||||||
|
|
||||||
void set(const std::string & str, bool append = false) override;
|
void set(const std::string & str, bool append = false) override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue