#include "dirent-util.h"
#include "dissect-image.h"
#include "efivars.h"
-#include "env-util.h"
#include "errno-util.h"
#include "extract-word.h"
#include "factory-reset.h"
#include "id128-util.h"
#include "image-policy.h"
#include "initrd-util.h"
+#include "install-file.h"
#include "io-util.h"
#include "json-util.h"
#include "libmount-util.h"
return 0;
}
-static usec_t epoch_or_infinity(void) {
- static usec_t cache;
- static bool cached = false;
- uint64_t epoch;
- int r;
-
- if (cached)
- return cache;
-
- r = secure_getenv_uint64("SOURCE_DATE_EPOCH", &epoch);
- if (r >= 0) {
- if (epoch <= UINT64_MAX / USEC_PER_SEC) { /* Overflow check */
- cached = true;
- return (cache = epoch * USEC_PER_SEC);
- }
- r = -ERANGE;
- }
- if (r != -ENXIO)
- log_debug_errno(r, "Failed to parse $SOURCE_DATE_EPOCH, ignoring: %m");
-
- cached = true;
- return (cache = USEC_INFINITY);
-}
-
static int file_is_denylisted(const char *source, Hashmap *denylist) {
_cleanup_close_ int pfd = -EBADF;
struct stat st, rst;
_cleanup_hashmap_free_ Hashmap *denylist = NULL;
_cleanup_hashmap_free_ Hashmap *subvolumes_by_source_inode = NULL;
_cleanup_close_ int sfd = -EBADF, pfd = -EBADF, tfd = -EBADF;
- usec_t ts = epoch_or_infinity();
+ usec_t ts = parse_source_date_epoch();
r = make_copy_files_denylist(context, p, line->source, line->target, &denylist);
if (r < 0)
}
STRV_FOREACH(d, override_dirs ?: p->make_directories) {
- r = mkdir_p_root_full(root, *d, UID_INVALID, GID_INVALID, 0755, epoch_or_infinity(), subvolumes);
+ r = mkdir_p_root_full(root, *d, UID_INVALID, GID_INVALID, 0755, parse_source_date_epoch(), subvolumes);
if (r < 0)
return log_error_errno(r, "Failed to create directory '%s' in file system: %m", *d);
}
#include "btrfs-util.h"
#include "chattr-util.h"
+#include "env-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fs-util.h"
#include "log.h"
#include "rm-rf.h"
#include "sync-util.h"
+#include "time-util.h"
static int fs_make_very_read_only(int fd) {
struct stat st;
return 0;
}
+
+usec_t parse_source_date_epoch(void) {
+ static usec_t cache;
+ static bool cached = false;
+ int r;
+
+ if (cached)
+ return cache;
+
+ uint64_t t;
+ r = secure_getenv_uint64("SOURCE_DATE_EPOCH", &t);
+ if (r >= 0) {
+ if (MUL_SAFE(&cache, t, USEC_PER_SEC)) {
+ cached = true;
+ return cache;
+ }
+
+ r = -ERANGE;
+ }
+ if (r != -ENXIO)
+ log_debug_errno(r, "Failed to parse $SOURCE_DATE_EPOCH, ignoring: %m");
+
+ cached = true;
+ return (cache = USEC_INFINITY);
+}
+
+usec_t source_date_epoch_or_now(void) {
+ usec_t epoch;
+
+ epoch = parse_source_date_epoch();
+ if (epoch != USEC_INFINITY)
+ return epoch;
+
+ return now(CLOCK_REALTIME);
+}
#include "copy.h"
#include "creds-util.h"
#include "dissect-image.h"
-#include "env-util.h"
#include "errno-util.h"
#include "extract-word.h"
#include "fd-util.h"
#include "fs-util.h"
#include "hashmap.h"
#include "image-policy.h"
+#include "install-file.h"
#include "label-util.h"
#include "libaudit-util.h"
#include "libcrypt-util.h"
return 0;
}
-static usec_t epoch_or_now(void) {
- uint64_t epoch;
-
- if (secure_getenv_uint64("SOURCE_DATE_EPOCH", &epoch) >= 0) {
- if (epoch > UINT64_MAX/USEC_PER_SEC) /* Overflow check */
- return USEC_INFINITY;
- return (usec_t) epoch * USEC_PER_SEC;
- }
-
- return now(CLOCK_REALTIME);
-}
-
static int write_temporary_shadow(
Context *c,
const char *shadow_path,
if (r < 0)
return log_debug_errno(r, "Failed to open temporary copy of %s: %m", shadow_path);
- lstchg = (long) (epoch_or_now() / USEC_PER_DAY);
+ lstchg = (long) (source_date_epoch_or_now() / USEC_PER_DAY);
original = fopen(shadow_path, "re");
if (original) {