numtide / nar-serve

Unpack and serve NAR file content on the fly
Apache License 2.0
32 stars 8 forks source link

Regression in 0.6.0: Can't fetch files inside archives: Leading slash #23

Closed chkno closed 8 months ago

chkno commented 1 year ago

From #20, the new 0.6.1's api/unpack/index.go, it looks like hdr.Path has /-prefixed names like /bin/hello, whereas the old 0.4.0's api/unpack/index.go, hdr.Name names are not /-prefixed, like bin/hello.

This breaks fetching single files from inside archives (server-side unpacking).

To Reproduce

Steps to reproduce the behavior:

  1. Fix the missing import os in nixos/tests/nar-serve.nix
  2. Run nix-build nixos/tests/nar-serve.nix

Expected behavior

Test passes

Actual behavior

Test fails: request returns 404 not found:

server: must succeed: curl -o hello -f http://localhost:8383/nix/store/cv79b81pjmva78whwwpr66l5mfj4pijh/bin/hello
server # [   29.716220] nar-serve[776]: 3 [cv79b81pjmva78whwwpr66l5mfj4pijh bin hello]
server # [   29.722451] nar-serve[776]: Fetching the narinfo: cv79b81pjmva78whwwpr66l5mfj4pijh.narinfo from: http://localhost/
server # [   29.732232] nar-serve[776]: narinfo StorePath: /nix/store/cv79b81pjmva78whwwpr66l5mfj4pijh-hello-2.12
server # [   29.736556] nar-serve[776]: URL: nar/14dp7chhq8akhgyqvyfkdwgg4d696agd0zga80ib0f382qhc6p8c.nar.xz
server # [   29.741487] nar-serve[776]: Compression: xz
server # [   29.743802] nar-serve[776]: FileHash: sha256:14dp7chhq8akhgyqvyfkdwgg4d696agd0zga80ib0f382qhc6p8c
server # [   29.748350] nar-serve[776]: FileSize: 43624
server # [   29.751017] nar-serve[776]: NarHash: sha256:0wbkw4v6ykfmm0jjp61z28f9nsf8wzx2cb4mz4g0gnv64sj2vsdk
server # [   29.754678] nar-serve[776]: NarSize: 181368
server # [   29.755824] nar-serve[776]: References: cv79b81pjmva78whwwpr66l5mfj4pijh-hello-2.12 f3qlm2873bxlhxns4lrmrinvbzn933pj-glibc-2.34-210
server # [   29.759341] nar-serve[776]: fetching the NAR: nar/14dp7chhq8akhgyqvyfkdwgg4d696agd0zga80ib0f382qhc6p8c.nar.xz
server # [   29.771493] nar-serve[776]: newPath bin/hello
server # [   29.778593] nar-serve[776]: [negroni] 2023-05-26T00:40:05Z | 404 |   63.002979ms | localhost:8383 | GET /nix/store/cv79b81pjmva78whwwpr66l5mfj4pijh/bin/hello
server # curl: (22) The requested URL returned error: 404
...
Exception: command `curl -o hello -f http://localhost:8383/nix/store/cv79b81pjmva78whwwpr66l5mfj4pijh/bin/hello` failed (exit code 22)

System information

NixOS 23.05beta78.04aaf851167

Additional context

Discovered in https://github.com/NixOS/nixpkgs/pull/178851#issuecomment-1563702699

Looks easily fixed: https://github.com/numtide/nar-serve/pull/24