Skip to content
This repository
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 64 lines (53 sloc) 1.217 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
package main

import (
"archive/tar"
"compress/gzip"
"fmt"
"log"
"net/http"
)

func doTarDocs(w http.ResponseWriter, req *http.Request,
path string) {

quit := make(chan bool)
defer close(quit)
ch := make(chan *namedFile)
cherr := make(chan error)

go pathGenerator(path, ch, cherr, quit)
go logErrors("tar", cherr)

w.Header().Set("Content-Disposition",
fmt.Sprintf("attachment; filename=%q", archiveFilename(path, "tar")))
w.Header().Set("Content-Type", "application/x-tar")

if canGzip(req) {
w.Header().Set("Content-Encoding", "gzip")
gz := gzip.NewWriter(w)
defer gz.Close()
w = &geezyWriter{w, gz}
}

w.WriteHeader(200)

tw := tar.NewWriter(w)
for nf := range ch {
if nf.err != nil {
log.Printf("Error on %v: %v", nf.name, nf.err)
continue
}

fh := tar.Header{
Name: nf.name,
Mode: 0644,
Size: nf.meta.Length,
ModTime: nf.meta.Modified,
}

err := tw.WriteHeader(&fh)
if err != nil {
log.Printf("Error writing header %#v: %v", fh, err)
continue
}

err = copyBlob(tw, nf.meta.OID)
if err != nil {
log.Printf("Error copying blob for %v: %v",
nf.name, err)
// Client will get a broken tar file
return
}
}
tw.Close()
}
Something went wrong with that request. Please try again.