aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-28 22:35:41 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-05-29 10:10:40 +0200
commitae7b56cd9a5ed8810828736fbb930a7c14ea44ca (patch)
treef20b1596729f29a60f36502324378388dafa2318 /src/libutil
parent0f840483c731f48983832f7f627909f8463f05f3 (diff)
Get last commit time of github flakes
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc18
-rw-r--r--src/libutil/util.hh6
2 files changed, 19 insertions, 5 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index f82f902fc..92c8957ff 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -22,6 +22,7 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/time.h>
#include <unistd.h>
#ifdef __APPLE__
@@ -552,20 +553,31 @@ Paths createDirs(const Path & path)
}
-void createSymlink(const Path & target, const Path & link)
+void createSymlink(const Path & target, const Path & link,
+ std::optional<time_t> mtime)
{
if (symlink(target.c_str(), link.c_str()))
throw SysError(format("creating symlink from '%1%' to '%2%'") % link % target);
+ if (mtime) {
+ struct timeval times[2];
+ times[0].tv_sec = *mtime;
+ times[0].tv_usec = 0;
+ times[1].tv_sec = *mtime;
+ times[1].tv_usec = 0;
+ if (lutimes(link.c_str(), times))
+ throw SysError("setting time of symlink '%s'", link);
+ }
}
-void replaceSymlink(const Path & target, const Path & link)
+void replaceSymlink(const Path & target, const Path & link,
+ std::optional<time_t> mtime)
{
for (unsigned int n = 0; true; n++) {
Path tmp = canonPath(fmt("%s/.%d_%s", dirOf(link), n, baseNameOf(link)));
try {
- createSymlink(target, tmp);
+ createSymlink(target, tmp, mtime);
} catch (SysError & e) {
if (e.errNo == EEXIST) continue;
throw;
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 35f9169f6..e05ef1e7d 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -142,10 +142,12 @@ Path getDataDir();
Paths createDirs(const Path & path);
/* Create a symlink. */
-void createSymlink(const Path & target, const Path & link);
+void createSymlink(const Path & target, const Path & link,
+ std::optional<time_t> mtime = {});
/* Atomically create or replace a symlink. */
-void replaceSymlink(const Path & target, const Path & link);
+void replaceSymlink(const Path & target, const Path & link,
+ std::optional<time_t> mtime = {});
/* Wrappers arount read()/write() that read/write exactly the