Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a tar target for streaming out files in bulk.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"archive/tar" | ||
"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-Type", "application/x-tar") | ||
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", fh) | ||
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() | ||
} |