From 1483c56582b264ac926929086722020003de5aed Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 10 Oct 2022 17:23:24 +0200 Subject: [PATCH] Patch libzip to return timestamps in the Unix epoch We're not even using those timestamps, but doing the conversion to local time takes a lot of time. For instance, this patch speeds up 'nix flake metadata nixpkgs` from 0.542s to 0.094s. --- flake.nix | 1 + libzip-unix-time.patch | 19 +++++++++++++++++++ src/libfetchers/zip-input-accessor.cc | 12 +----------- 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 libzip-unix-time.patch diff --git a/flake.nix b/flake.nix index be58c9b74..06d60abd7 100644 --- a/flake.nix +++ b/flake.nix @@ -115,6 +115,7 @@ (libzip.overrideDerivation (old: { # Temporary workaround for https://github.com/NixOS/nixpkgs/pull/178755 cmakeFlags = old.cmakeFlags or [] ++ [ "-DBUILD_REGRESS=0" ]; + patches = [ ./libzip-unix-time.patch ]; })) boost lowdown-nix diff --git a/libzip-unix-time.patch b/libzip-unix-time.patch new file mode 100644 index 000000000..4183b366e --- /dev/null +++ b/libzip-unix-time.patch @@ -0,0 +1,19 @@ +commit 26e8c76ca84999fa5c0e46a9fc3aa7de80be2e9c +Author: Eelco Dolstra +Date: Mon Oct 10 17:12:47 2022 +0200 + + Return time_t in the Unix epoch + +diff --git a/lib/zip_dirent.c b/lib/zip_dirent.c +index 7fd2f7ce..5c050b4c 100644 +--- a/lib/zip_dirent.c ++++ b/lib/zip_dirent.c +@@ -1018,7 +1018,7 @@ _zip_d2u_time(zip_uint16_t dtime, zip_uint16_t ddate) { + tm.tm_min = (dtime >> 5) & 63; + tm.tm_sec = (dtime << 1) & 62; + +- return mktime(&tm); ++ return timegm(&tm); + } + + diff --git a/src/libfetchers/zip-input-accessor.cc b/src/libfetchers/zip-input-accessor.cc index 249b17fe2..8da601b77 100644 --- a/src/libfetchers/zip-input-accessor.cc +++ b/src/libfetchers/zip-input-accessor.cc @@ -35,7 +35,7 @@ struct ZipInputAccessor : InputAccessor : zipPath(_zipPath) { int error; - zipFile = zip_open(zipPath.c_str(), 0, &error); + zipFile = zip_open(zipPath.c_str(), ZIP_RDONLY, &error); if (!zipFile) { char errorMsg[1024]; zip_error_to_str(errorMsg, sizeof errorMsg, error, errno); @@ -68,16 +68,6 @@ struct ZipInputAccessor : InputAccessor if (!slash) continue; members.emplace(slash, sb); } - - #if 0 - /* Sigh, libzip returns a local time, so convert to Unix - time. */ - if (lastModified) { - struct tm tm; - localtime_r(&lastModified, &tm); - lastModified = timegm(&tm); - } - #endif } ~ZipInputAccessor()