Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5230,7 +5230,7 @@ void EvalState::createBaseEnv(const EvalSettings & evalSettings)
});

if (!settings.pureEval) {
v.mkInt(time(0));
v.mkInt(time(nullptr));
}
addConstant(
"__currentTime",
Expand Down
4 changes: 2 additions & 2 deletions src/libfetchers/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct CacheImpl : Cache
void upsert(const Key & key, const Attrs & value) override
{
_state.lock()
->upsert.use()(key.first)(attrsToJSON(key.second).dump())(attrsToJSON(value).dump())(time(0))
->upsert.use()(key.first)(attrsToJSON(key.second).dump())(attrsToJSON(value).dump())(time(nullptr))
.exec();
}

Expand Down Expand Up @@ -99,7 +99,7 @@ struct CacheImpl : Cache
debug("using cache entry '%s:%s' -> '%s'", key.first, keyJSON, valueJSON);

return Result{
.expired = settings.tarballTtl.get() == 0 || timestamp + settings.tarballTtl < time(0),
.expired = settings.tarballTtl.get() == 0 || timestamp + settings.tarballTtl < time(nullptr),
.value = jsonToAttrs(nlohmann::json::parse(valueJSON)),
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static std::optional<std::string> readHeadCached(const Settings & settings, cons
std::filesystem::path cacheDir = getCachePath(actualUrl, shallow);
std::filesystem::path headRefFile = cacheDir / "HEAD";

time_t now = time(0);
time_t now = time(nullptr);
auto st = maybeStat(headRefFile);
std::optional<std::string> cachedRef;
if (st) {
Expand Down Expand Up @@ -830,7 +830,7 @@ struct GitInputScheme : InputScheme
auto localRefFile = ref.compare(0, 5, "refs/") == 0 ? cacheDir / ref : cacheDir / "refs/heads" / ref;

bool doFetch = false;
time_t now = time(0);
time_t now = time(nullptr);

/* If a rev was specified, we need to fetch if it's not in the
repo. */
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/build/derivation-building-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ Goal::Co DerivationBuildingGoal::buildWithHook(
fds.insert(hook->builderOut.readSide.get());
worker.childStarted(shared_from_this(), fds, false, false);

buildResult.startTime = time(0); // inexact
buildResult.startTime = time(nullptr); // inexact

auto msg =
fmt(buildMode == bmRepair ? "repairing outputs of '%s'"
Expand Down Expand Up @@ -709,7 +709,7 @@ Goal::Co DerivationBuildingGoal::buildWithHook(
debug("build hook for '%s' finished", worker.store.printStorePath(drvPath));

buildResult.timesBuilt++;
buildResult.stopTime = time(0);
buildResult.stopTime = time(nullptr);

/* So the child is gone now. */
worker.childTerminated(this);
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/include/nix/store/sqlite.hh
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void handleSQLiteBusy(const SQLiteBusy & e, time_t & nextWarning);
template<typename T, typename F>
T retrySQLite(F && fun)
{
time_t nextWarning = time(0) + 1;
time_t nextWarning = time(nullptr) + 1;

while (true) {
try {
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 @@ -688,7 +688,7 @@ uint64_t LocalStore::addValidPath(State & state, const ValidPathInfo & info)

state.stmts->RegisterValidPath
.use()(printStorePath(info.path))(info.narHash.to_string(HashFormat::Base16, true))(
info.registrationTime == 0 ? time(0) : info.registrationTime)(
info.registrationTime == 0 ? time(nullptr) : info.registrationTime)(
info.deriver ? printStorePath(*info.deriver) : "",
(bool) info.deriver)(info.narSize, info.narSize != 0)(info.ultimate ? 1 : 0, info.ultimate)(
concatStringsSep(" ", Signature::toStrings(info.sigs)),
Expand Down
23 changes: 14 additions & 9 deletions src/libstore/nar-info-disk-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct NarInfoDiskCacheImpl : NarInfoDiskCache

/* Periodically purge expired entries from the database. */
retrySQLite<void>([&]() {
auto now = time(0);
auto now = time(nullptr);

SQLiteStmt queryLastPurge(state->db, "select value from LastPurge");
auto queryLastPurge_(queryLastPurge.use());
Expand Down Expand Up @@ -181,7 +181,11 @@ struct NarInfoDiskCacheImpl : NarInfoDiskCache
{
auto i = state.caches.find(uri);
if (i == state.caches.end()) {
auto queryCache(state.queryCache.use()(uri)(time(0) - settings.ttlMeta));
/* Important: always use int64_t even on 32 bit systems. Otherwise
the the subtraction would promote time_t to unsigned if time_t is
32 bit. */
auto timestamp = static_cast<int64_t>(time(nullptr)) - static_cast<int64_t>(settings.ttlMeta.get());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think being extra explicit here is nice. C/C++ integral promotion rules are too confusing to get right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agreed

auto queryCache(state.queryCache.use()(uri)(timestamp));
if (!queryCache.next())
return std::nullopt;
auto cache = Cache{
Expand Down Expand Up @@ -217,7 +221,7 @@ struct NarInfoDiskCacheImpl : NarInfoDiskCache
};

{
auto r(state->insertCache.use()(uri)(time(0))(storeDir) (wantMassQuery) (priority));
auto r(state->insertCache.use()(uri)(time(nullptr))(storeDir) (wantMassQuery) (priority));
if (!r.next()) {
unreachable();
}
Expand Down Expand Up @@ -251,7 +255,7 @@ struct NarInfoDiskCacheImpl : NarInfoDiskCache

auto & cache(getCache(*state, uri));

auto now = time(0);
auto now = time(nullptr);

auto queryNAR(
state->queryNAR.use()(cache.id)(hashPart) (now - settings.ttlNegative)(now - settings.ttlPositive));
Expand Down Expand Up @@ -292,7 +296,7 @@ struct NarInfoDiskCacheImpl : NarInfoDiskCache

auto & cache(getCache(*state, uri));

auto now = time(0);
auto now = time(nullptr);

auto queryRealisation(state->queryRealisation.use()(cache.id)(id.to_string())(
now - settings.ttlNegative)(now - settings.ttlPositive));
Expand Down Expand Up @@ -338,11 +342,11 @@ struct NarInfoDiskCacheImpl : NarInfoDiskCache
HashFormat::Nix32, true))(info->narSize)(concatStringsSep(" ", info->shortRefs()))(
info->deriver ? std::string(info->deriver->to_string()) : "",
(bool) info->deriver)(concatStringsSep(" ", Signature::toStrings(info->sigs)))(
renderContentAddress(info->ca))(time(0))
renderContentAddress(info->ca))(time(nullptr))
.exec();

} else {
state->insertMissingNAR.use()(cache.id)(hashPart) (time(0)).exec();
state->insertMissingNAR.use()(cache.id)(hashPart) (time(nullptr)).exec();
}
});
}
Expand All @@ -355,7 +359,8 @@ struct NarInfoDiskCacheImpl : NarInfoDiskCache
auto & cache(getCache(*state, uri));

state->insertRealisation
.use()(cache.id)(realisation.id.to_string())(static_cast<nlohmann::json>(realisation).dump())(time(0))
.use()(cache.id)(realisation.id.to_string())(static_cast<nlohmann::json>(realisation).dump())(
time(nullptr))
.exec();
});
}
Expand All @@ -366,7 +371,7 @@ struct NarInfoDiskCacheImpl : NarInfoDiskCache
auto state(_state.lock());

auto & cache(getCache(*state, uri));
state->insertMissingRealisation.use()(cache.id)(id.to_string())(time(0)).exec();
state->insertMissingRealisation.use()(cache.id)(id.to_string())(time(nullptr)).exec();
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/profiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ time_t parseOlderThanTimeSpec(std::string_view timeSpec)
if (timeSpec.empty() || timeSpec[timeSpec.size() - 1] != 'd')
throw UsageError("invalid number of days specifier '%1%', expected something like '14d'", timeSpec);

time_t curTime = time(0);
time_t curTime = time(nullptr);
auto strDays = timeSpec.substr(0, timeSpec.size() - 1);
auto days = string2Int<int>(strDays);

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ SQLiteTxn::~SQLiteTxn()

void handleSQLiteBusy(const SQLiteBusy & e, time_t & nextWarning)
{
time_t now = time(0);
time_t now = time(nullptr);
if (now > nextWarning) {
nextWarning = now + 10;
logWarning({.msg = e.info().msg});
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/unix/build/derivation-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ SingleDrvOutputs DerivationBuilderImpl::unprepareBuild()
debug("builder process for '%s' finished", store.printStorePath(drvPath));

buildResult.timesBuilt++;
buildResult.stopTime = time(0);
buildResult.stopTime = time(nullptr);

/* So the child is gone now. */
miscMethods->childTerminated();
Expand Down Expand Up @@ -872,7 +872,7 @@ std::optional<Descriptor> DerivationBuilderImpl::startBuild()
if (unlockpt(builderOut.get()))
throw SysError("unlocking pseudoterminal");

buildResult.startTime = time(0);
buildResult.startTime = time(nullptr);

/* Start a child process to build the derivation. */
startChild();
Expand Down
Loading