From 0a48b45c5af7787e131d74e1f947149211de78d8 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Wed, 30 Oct 2024 20:20:59 -0400 Subject: [PATCH] xar: fix Linux build on staging-next --- pkgs/by-name/xa/xar/package.nix | 6 ++- .../0020-Fall-back-to-readlink-on-Linux.patch | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 pkgs/by-name/xa/xar/patches/0020-Fall-back-to-readlink-on-Linux.patch diff --git a/pkgs/by-name/xa/xar/package.nix b/pkgs/by-name/xa/xar/package.nix index 3b4aafa43b20..455576526dd5 100644 --- a/pkgs/by-name/xa/xar/package.nix +++ b/pkgs/by-name/xa/xar/package.nix @@ -48,7 +48,11 @@ stdenv.mkDerivation (finalAttrs: { # # … # rm -r ../pkgs/by-name/xa/xar/patches # git format-patch --zero-commit --output-directory ../pkgs/by-name/xa/xar/patches main - patches = lib.filesystem.listFilesRecursive ./patches; + patches = + # Avoid Darwin rebuilds on staging-next + lib.filter ( + p: stdenv.hostPlatform.isDarwin -> baseNameOf p != "0020-Fall-back-to-readlink-on-Linux.patch" + ) (lib.filesystem.listFilesRecursive ./patches); # We do not use or modify files outside of the xar subdirectory. patchFlags = [ "-p2" ]; diff --git a/pkgs/by-name/xa/xar/patches/0020-Fall-back-to-readlink-on-Linux.patch b/pkgs/by-name/xa/xar/patches/0020-Fall-back-to-readlink-on-Linux.patch new file mode 100644 index 000000000000..02b96aee1be3 --- /dev/null +++ b/pkgs/by-name/xa/xar/patches/0020-Fall-back-to-readlink-on-Linux.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Wed, 30 Oct 2024 20:19:20 -0400 +Subject: [PATCH 20/20] Fall back to readlink on Linux + +--- + xar/lib/archive.c | 21 +++++++++++++++++++++ + 1 file changed, 21 insertions(+) + +diff --git a/xar/lib/archive.c b/xar/lib/archive.c +index b7f9cbf..3a79c74 100644 +--- a/xar/lib/archive.c ++++ b/xar/lib/archive.c +@@ -507,10 +507,31 @@ xar_t xar_fdopen_digest_verify(int fd, int32_t flags, void *expected_toc_digest, + // If there are hardlinks, the path we pick is the most recently opened by + // the filesystem; which is effectively random. + char path_buff[PATH_MAX]; ++#if defined(__APPLE__) + if (fcntl(fd, F_GETPATH, path_buff) < 0) { + close(fd); + return NULL; + } ++#elif defined(__linux__) ++ // Linux has to get the path to the file via `/proc`. ++ char proc_buff[PATH_MAX]; ++ if (snprintf(proc_buff, PATH_MAX, "/proc/self/fd/%i", fd) < 0) { ++ close(fd); ++ return NULL; ++ } ++ if (readlink(proc_buff, &path_buff, PATH_MAX) < 0) { ++ close(fd); ++ return NULL; ++ } ++ // The filename is the file’s when the fd was created. Check to make sure it still exists. ++ struct stat stat_buff; ++ if (stat(path_buff, &stat_buff) < 0) { ++ close(fd); ++ return NULL; ++ } ++#else ++#error "Unknown platform. Please update with an implementation of `F_GETPATH`." ++#endif + + // Don't trust the position of the descriptor we were given, reset it back to 0 + if (lseek(fd, 0, SEEK_SET) != 0) { +-- +2.47.0 +