diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-07-27 17:15:09 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-07-27 17:23:29 +0200 |
commit | 9f64cb89cbbd0cd0540ad99e3578b6cecd385a81 (patch) | |
tree | 8625dc560b8eb35ec5434dc8143b2f35244615e6 /src | |
parent | 69deca194ec789fa63d222bbd6549dab73328022 (diff) |
builtins.fetchgit: Respect tarball-ttl
I.e. if the local ref is more recent than tarball-ttl seconds, then
don't check the remote.
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/primops/fetchgit.cc | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/libexpr/primops/fetchgit.cc b/src/libexpr/primops/fetchgit.cc index b64a00b61..3ab2644c8 100644 --- a/src/libexpr/primops/fetchgit.cc +++ b/src/libexpr/primops/fetchgit.cc @@ -4,6 +4,8 @@ #include "store-api.hh" #include "pathlocks.hh" +#include <sys/time.h> + namespace nix { Path exportGit(ref<Store> store, const std::string & uri, const std::string & rev) @@ -24,7 +26,23 @@ Path exportGit(ref<Store> store, const std::string & uri, const std::string & re Path localRefFile = cacheDir + "/refs/heads/" + localRef; - runProgram("git", true, { "-C", cacheDir, "fetch", "--force", uri, rev + ":" + localRef }); + /* If the local ref is older than ‘tarball-ttl’ seconds, do a git + fetch to update the local ref to the remote ref. */ + time_t now = time(0); + struct stat st; + if (stat(localRefFile.c_str(), &st) != 0 || + st.st_mtime < now - settings.tarballTtl) + { + runProgram("git", true, { "-C", cacheDir, "fetch", "--force", uri, rev + ":" + localRef }); + + struct timeval times[2]; + times[0].tv_sec = now; + times[0].tv_usec = 0; + times[1].tv_sec = now; + times[1].tv_usec = 0; + + utimes(localRefFile.c_str(), times); + } std::string commitHash = chomp(readFile(localRefFile)); |