From bc38abb46a798fd998f6004562d495a9c9587061 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Sat, 3 Apr 2021 17:32:04 +0000 Subject: [PATCH] curl: add patch for curling directories using file:/// nix relies on using curl to fetch directories using the file scheme, which got broken by the most recent curl update in https://github.com/curl/curl/commit/1e5cec3297b143c1884fc0069afe247091122c2e - which no longer provides a content-length for directories, but in so doing causes *any* fetch of a directory to return "Couldn't resume download (36)" (which is easily testable using the CLI) --- .../curl/curl-accept-ranges-not-on-dirs.patch | 29 +++++++++++++++++++ pkgs/tools/networking/curl/default.nix | 4 +++ 2 files changed, 33 insertions(+) create mode 100644 pkgs/tools/networking/curl/curl-accept-ranges-not-on-dirs.patch diff --git a/pkgs/tools/networking/curl/curl-accept-ranges-not-on-dirs.patch b/pkgs/tools/networking/curl/curl-accept-ranges-not-on-dirs.patch new file mode 100644 index 0000000000000..3423df3e75e5d --- /dev/null +++ b/pkgs/tools/networking/curl/curl-accept-ranges-not-on-dirs.patch @@ -0,0 +1,29 @@ +diff -r -u curl-7.76.0-pristine/lib/file.c curl-7.76.0/lib/file.c +--- curl-7.76.0-pristine/lib/file.c 2021-02-22 11:47:54.000000000 +0000 ++++ curl-7.76.0/lib/file.c 2021-04-03 17:23:47.677582417 +0000 +@@ -419,10 +419,12 @@ + return result; + } + +- result = Curl_client_write(data, CLIENTWRITE_HEADER, +- (char *)"Accept-ranges: bytes\r\n", 0); +- if(result) +- return result; ++ if(!S_ISDIR(statbuf.st_mode)) { ++ result = Curl_client_write(data, CLIENTWRITE_HEADER, ++ (char *)"Accept-ranges: bytes\r\n", 0); ++ if(result) ++ return result; ++ } + + filetime = (time_t)statbuf.st_mtime; + result = Curl_gmtime(filetime, &buffer); +@@ -464,7 +466,7 @@ + data->state.resume_from += (curl_off_t)statbuf.st_size; + } + +- if(data->state.resume_from <= expected_size) ++ if(data->state.resume_from <= expected_size || data->state.resume_from == 0) + expected_size -= data->state.resume_from; + else { + failf(data, "failed to resume file:// transfer"); diff --git a/pkgs/tools/networking/curl/default.nix b/pkgs/tools/networking/curl/default.nix index 918abcf83b40e..b4fe492fc17cb 100644 --- a/pkgs/tools/networking/curl/default.nix +++ b/pkgs/tools/networking/curl/default.nix @@ -45,6 +45,10 @@ stdenv.mkDerivation rec { sha256 = "16n466an72fkick4j1phfg5a8p7f96vbnw80bgbr05bh6cvgx6z2"; }; + patches = [ + ./curl-accept-ranges-not-on-dirs.patch + ]; + outputs = [ "bin" "dev" "out" "man" "devdoc" ]; separateDebugInfo = stdenv.isLinux;