summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/add.c2
-rw-r--r--src/apk.c9
-rw-r--r--src/apk_defines.h3
-rw-r--r--src/archive.c2
-rw-r--r--src/database.c4
-rw-r--r--test/basic8.test2
-rw-r--r--test/basic9.test2
7 files changed, 18 insertions, 6 deletions
diff --git a/src/add.c b/src/add.c
index 7df8197..2d342ab 100644
--- a/src/add.c
+++ b/src/add.c
@@ -108,7 +108,7 @@ static int add_main(void *ctx, struct apk_database *db, struct apk_string_array
if (virtdep.name->name[0] != '.' && non_repository_check(db))
return -1;
- time(&now);
+ now = apk_time();
localtime_r(&now, &tm);
strftime(ver, sizeof ver, "%Y%m%d.%H%M%S", &tm);
diff --git a/src/apk.c b/src/apk.c
index 2819281..069f4c0 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -47,6 +47,15 @@ static struct apk_string_array *test_repos;
char **apk_argv;
+time_t apk_time(void)
+{
+#ifdef TEST_MODE
+ return 1559567666;
+#else
+ return time(NULL);
+#endif
+}
+
static void version(void)
{
printf("apk-tools " APK_VERSION ", compiled for " APK_DEFAULT_ARCH ".\n"
diff --git a/src/apk_defines.h b/src/apk_defines.h
index c7ab7e6..b008b51 100644
--- a/src/apk_defines.h
+++ b/src/apk_defines.h
@@ -14,6 +14,7 @@
#include <endian.h>
#include <string.h>
+#include <time.h>
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define BIT(x) (1 << (x))
@@ -121,6 +122,8 @@ extern char **apk_argv;
#define APK_MAX_TAGS 16 /* see solver; unsigned short */
#define APK_CACHE_CSUM_BYTES 4
+time_t apk_time(void);
+
static inline size_t apk_calc_installed_size(size_t size)
{
const size_t bsize = 4 * 1024;
diff --git a/src/archive.c b/src/archive.c
index 724410c..86f2e3d 100644
--- a/src/archive.c
+++ b/src/archive.c
@@ -396,7 +396,7 @@ int apk_tar_write_entry(struct apk_ostream *os, const struct apk_file_info *ae,
PUT_OCTAL(buf.uid, ae->uid);
PUT_OCTAL(buf.gid, ae->gid);
PUT_OCTAL(buf.mode, ae->mode & 07777);
- PUT_OCTAL(buf.mtime, ae->mtime ?: time(NULL));
+ PUT_OCTAL(buf.mtime, ae->mtime ?: apk_time());
/* Checksum */
strcpy(buf.magic, "ustar ");
diff --git a/src/database.c b/src/database.c
index 5bffb43..4e41f21 100644
--- a/src/database.c
+++ b/src/database.c
@@ -624,7 +624,7 @@ int apk_cache_download(struct apk_database *db, struct apk_repository *repo,
char tmpcacheitem[128], *cacheitem = &tmpcacheitem[tmpprefix.len];
apk_blob_t b = APK_BLOB_BUF(tmpcacheitem);
int r, fd;
- time_t now = time(NULL);
+ time_t now = apk_time();
apk_blob_push_blob(&b, tmpprefix);
if (pkg != NULL)
@@ -1005,7 +1005,7 @@ static int apk_db_scriptdb_write(struct apk_database *db, struct apk_ostream *os
char filename[256];
apk_blob_t bfn;
int r, i;
- time_t now = time(NULL);
+ time_t now = apk_time();
list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list) {
pkg = ipkg->pkg;
diff --git a/test/basic8.test b/test/basic8.test
index 4d5ebb2..ce17f7f 100644
--- a/test/basic8.test
+++ b/test/basic8.test
@@ -2,5 +2,5 @@
--no-network
add -t .virtual
@EXPECT
-(1/1) Installing .virtual (0)
+(1/1) Installing .virtual (20190603.161426)
OK: 0 MiB in 0 packages
diff --git a/test/basic9.test b/test/basic9.test
index 34bcb63..dde4f0b 100644
--- a/test/basic9.test
+++ b/test/basic9.test
@@ -4,5 +4,5 @@
--test-world a
add -t .virtual a
@EXPECT
-(1/1) Installing .virtual (0)
+(1/1) Installing .virtual (20190603.161426)
OK: 0 MiB in 2 packages