diff options
Diffstat (limited to 'apt-private/private-utils.cc')
-rw-r--r-- | apt-private/private-utils.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/apt-private/private-utils.cc b/apt-private/private-utils.cc index 775bf7e79..5863925b9 100644 --- a/apt-private/private-utils.cc +++ b/apt-private/private-utils.cc @@ -1,11 +1,13 @@ #include <config.h> #include <apt-pkg/configuration.h> +#include <apt-pkg/error.h> #include <apt-pkg/fileutl.h> #include <apt-private/private-utils.h> #include <cstdlib> +#include <sstream> #include <unistd.h> // DisplayFileInPager - Display File with pager /*{{{*/ @@ -74,3 +76,23 @@ bool EditFileInSensibleEditor(std::string const &filename) return ExecWait(Process, "editor", false); } /*}}}*/ +time_t GetSecondsSinceEpoch() /*{{{*/ +{ + auto const source_date_epoch = getenv("SOURCE_DATE_EPOCH"); + if (source_date_epoch == nullptr) + return time(nullptr); + + time_t epoch; + std::stringstream ss(source_date_epoch); + ss >> epoch; + + if (ss.fail() || !ss.eof()) + { + _error->Warning("Environment variable SOURCE_DATE_EPOCH was ignored as it has an invalid value: \"%s\"", + source_date_epoch); + return time(nullptr); + } + + return epoch; +} + /*}}}*/ |