From 06801cb4f087f60d611295bbdf9e60adf2816cf2 Mon Sep 17 00:00:00 2001 From: Tyson Whitehead Date: Tue, 23 Jan 2018 23:47:04 -0500 Subject: [PATCH] temporary: nix: Work around for broken stat size #1645 --- temporary/all-temporary.nix | 5 +++++ temporary/nix/stat.patch | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 temporary/nix/stat.patch diff --git a/temporary/all-temporary.nix b/temporary/all-temporary.nix index 76fc72b..125f2ab 100644 --- a/temporary/all-temporary.nix +++ b/temporary/all-temporary.nix @@ -7,4 +7,9 @@ self: super: pkgs: with pkgs; { + # https://github.com/NixOS/nix/pull/1645 + nixStable = super.nixStable.overrideAttrs + ( attrs: { patches = attrs.patches or [] ++ [ ./nix/stat.patch ]; } ); + nix = super.nix.overrideAttrs + ( attrs: { patches = attrs.patches or [] ++ [ ./nix/stat.patch ]; } ); } diff --git a/temporary/nix/stat.patch b/temporary/nix/stat.patch new file mode 100644 index 0000000..bee5a3c --- /dev/null +++ b/temporary/nix/stat.patch @@ -0,0 +1,33 @@ +diff --git a/src/libutil/util.cc b/src/libutil/util.cc +index 0b11330..4c1dff2 100644 +--- a/src/libutil/util.cc ++++ b/src/libutil/util.cc +@@ -198,17 +198,17 @@ bool pathExists(const Path & path) + Path readLink(const Path & path) + { + checkInterrupt(); +- struct stat st = lstat(path); +- if (!S_ISLNK(st.st_mode)) +- throw Error(format("‘%1%’ is not a symlink") % path); +- char buf[st.st_size]; +- ssize_t rlsize = readlink(path.c_str(), buf, st.st_size); +- if (rlsize == -1) +- throw SysError(format("reading symbolic link ‘%1%’") % path); +- else if (rlsize > st.st_size) +- throw Error(format("symbolic link ‘%1%’ size overflow %2% > %3%") +- % path % rlsize % st.st_size); +- return string(buf, st.st_size); ++ for (ssize_t bufSize = PATH_MAX/4; true; bufSize += bufSize/2) { ++ char buf[bufSize]; ++ ssize_t rlSize = readlink(path.c_str(), buf, bufSize); ++ if (rlSize == -1) ++ if (errno == EINVAL) ++ throw Error(format("'%1%' is not a symlink") % path); ++ else ++ throw SysError(format("reading symbolic link '%1%'") % path); ++ else if (rlSize < bufSize) ++ return string(buf, rlSize); ++ } + } + +