Skip to content

Commit

Permalink
go.mod: use go-nix from nix-community, bump (#20)
Browse files Browse the repository at this point in the history
nix-community/go-nix#27 moved this to
nix-community, and there have been some API changes in the meantime.
  • Loading branch information
flokli authored Mar 16, 2022
1 parent 64b2de3 commit 89c7abb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
33 changes: 19 additions & 14 deletions api/unpack/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"path/filepath"
"strings"

"github.com/numtide/go-nix/nar"
"github.com/numtide/go-nix/nar/narinfo"
"github.com/nix-community/go-nix/pkg/nar"
"github.com/nix-community/go-nix/pkg/nar/narinfo"
"github.com/numtide/nar-serve/libstore"

"github.com/ulikunitz/xz"
Expand Down Expand Up @@ -88,7 +88,12 @@ func Handler(w http.ResponseWriter, req *http.Request) {

// TODO: try to load .ls files to speed-up the file lookups

narReader := nar.NewReader(r)
narReader, err := nar.NewReader(r)
if err != nil {
http.Error(w, err.Error(), 500)
return
}

newPath := strings.Join(components[1:], "/")

fmt.Println("newPath", newPath)
Expand All @@ -105,11 +110,11 @@ func Handler(w http.ResponseWriter, req *http.Request) {
}

// we've got a match!
if hdr.Name == newPath {
if hdr.Path == newPath {
switch hdr.Type {
case nar.TypeDirectory:
w.Header().Set("Content-Type", "text/html")
fmt.Fprintf(w, "<p>%s is a directory:</p><ol>", hdr.Name)
fmt.Fprintf(w, "<p>%s is a directory:</p><ol>", hdr.Path)
flush(w)
for {
hdr2, err := narReader.Next()
Expand All @@ -121,23 +126,23 @@ func Handler(w http.ResponseWriter, req *http.Request) {
}
}

if !strings.HasPrefix(hdr2.Name, hdr.Name) {
if !strings.HasPrefix(hdr2.Path, hdr.Path) {
break
}

var label string
switch hdr2.Type {
case nar.TypeDirectory:
label = hdr2.Name + "/"
label = hdr2.Path + "/"
case nar.TypeSymlink:
label = hdr2.Name + " -> " + absSymlink(narinfo, hdr2)
label = hdr2.Path + " -> " + absSymlink(narinfo, hdr2)
case nar.TypeRegular:
label = hdr2.Name
label = hdr2.Path
default:
http.Error(w, fmt.Sprintf("BUG: unknown NAR header type: %s", hdr.Type), 500)
}

fmt.Fprintf(w, "<li><a href='%s'>%s</a></li>", filepath.Join(narinfo.StorePath, hdr2.Name), label)
fmt.Fprintf(w, "<li><a href='%s'>%s</a></li>", filepath.Join(narinfo.StorePath, hdr2.Path), label)
flush(w)
}
case nar.TypeSymlink:
Expand All @@ -153,7 +158,7 @@ func Handler(w http.ResponseWriter, req *http.Request) {
case nar.TypeRegular:
// TODO: ETag header matching. Use the NAR file name as the ETag
// TODO: expose the executable flag somehow?
ctype := mime.TypeByExtension(filepath.Ext(hdr.Name))
ctype := mime.TypeByExtension(filepath.Ext(hdr.Path))
if ctype == "" {
ctype = "application/octet-stream"
// TODO: use http.DetectContentType as a fallback
Expand Down Expand Up @@ -201,11 +206,11 @@ func getNarInfo(ctx context.Context, key string) (*narinfo.NarInfo, error) {
}

func absSymlink(narinfo *narinfo.NarInfo, hdr *nar.Header) string {
if filepath.IsAbs(hdr.Linkname) {
return hdr.Linkname
if filepath.IsAbs(hdr.LinkTarget) {
return hdr.LinkTarget
}

return filepath.Join(narinfo.StorePath, filepath.Dir(hdr.Name), hdr.Linkname)
return filepath.Join(narinfo.StorePath, filepath.Dir(hdr.Path), hdr.LinkTarget)
}

func flush(rw http.ResponseWriter) {
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ require (
cloud.google.com/go/iam v0.1.0 // indirect
cloud.google.com/go/storage v1.18.2
github.com/aws/aws-sdk-go v1.42.34
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/numtide/go-nix v0.0.0-20211215191921-37a8ad2f9e4f
github.com/nix-community/go-nix v0.0.0-20220316150926-3545e7c84bb2
github.com/stretchr/testify v1.7.0
github.com/ulikunitz/xz v0.5.10
github.com/urfave/negroni v1.0.0
Expand Down
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/participle/v2 v2.0.0-alpha7/go.mod h1:NumScqsC42o9x+dGj8/YqsIfhrIQjFEOFovxotbBirA=
github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
github.com/alecthomas/repr v0.0.0-20200325044227-4184120f674c/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/aws/aws-sdk-go v1.33.13/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.42.34 h1:fqGAiKmCSRY1rEa4G9VqgkKKbNmLKYq5dKmLtQkvYi8=
github.com/aws/aws-sdk-go v1.42.34/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -92,7 +94,6 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -175,7 +176,6 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
Expand All @@ -188,8 +188,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/numtide/go-nix v0.0.0-20211215191921-37a8ad2f9e4f h1:tBFsbD8RZmpPG/f8A6ZrTUXXWXTvCdDxBJ+FBWizYKo=
github.com/numtide/go-nix v0.0.0-20211215191921-37a8ad2f9e4f/go.mod h1:QdjLlYQnNqfJRhTF9YJTfIt902z6yufXmI1xy+PwGMg=
github.com/nix-community/go-nix v0.0.0-20220316150926-3545e7c84bb2 h1:T5Sx5bqZgy7jw4NbhVdQ5Y0hze6gLjDKBWZ3iRTywLA=
github.com/nix-community/go-nix v0.0.0-20220316150926-3545e7c84bb2/go.mod h1:WYuG8T1RzKZiENnXnrdTgmKAICsPN1mhIVWPpRaFSEc=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down

0 comments on commit 89c7abb

Please sign in to comment.