update remoteGetSector
This commit is contained in:
parent
1a9b5760a7
commit
19bd5beb96
24
extern/sector-storage/stores/http_handler.go
vendored
24
extern/sector-storage/stores/http_handler.go
vendored
@ -205,32 +205,30 @@ func (handler *FetchHandler) remoteGetSector(w http.ResponseWriter, r *http.Requ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var rd io.Reader
|
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
rd, err = tarutil.TarDirectory(path)
|
if _, has := r.Header["Range"]; has {
|
||||||
w.Header().Set("Content-Type", "application/x-tar")
|
log.Error("Range not supported on directories")
|
||||||
} else {
|
w.WriteHeader(500)
|
||||||
rd, err = os.OpenFile(path, os.O_RDONLY, 0644) // nolint
|
return
|
||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rd, err := tarutil.TarDirectory(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("%+v", err)
|
log.Errorf("%+v", err)
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !stat.IsDir() {
|
|
||||||
defer func() {
|
|
||||||
if err := rd.(*os.File).Close(); err != nil {
|
|
||||||
log.Errorf("closing source file: %+v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/x-tar")
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
if _, err := io.CopyBuffer(w, rd, make([]byte, CopyBuf)); err != nil {
|
if _, err := io.CopyBuffer(w, rd, make([]byte, CopyBuf)); err != nil {
|
||||||
log.Errorf("%+v", err)
|
log.Errorf("%+v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
|
http.ServeFile(w, r, path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *FetchHandler) remoteDeleteSector(w http.ResponseWriter, r *http.Request) {
|
func (handler *FetchHandler) remoteDeleteSector(w http.ResponseWriter, r *http.Request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user