cmd/htpacker: cope with zero-length input files
Sometimes we might be asked to serve up a zero-length input file, typically from some machine-generated CSS etc. We make some very rudimentary guess about the content-type the caller wanted and skip the mmap(2) call.
This commit is contained in:
parent
52213cf67e
commit
1b84160dcf
2 changed files with 21 additions and 8 deletions
|
|
@ -325,11 +325,14 @@ func (p *packer) packFile(path string, fileToPack FileToPack) {
|
|||
return
|
||||
}
|
||||
|
||||
data, err := unix.Mmap(int(f.Fd()), 0, int(fi.Size()),
|
||||
unix.PROT_READ, unix.MAP_SHARED)
|
||||
if err != nil {
|
||||
p.Abort(fmt.Errorf("mmap %s: %v", fileToPack.Filename, err))
|
||||
return
|
||||
var data []byte
|
||||
if fi.Size() > 0 {
|
||||
data, err = unix.Mmap(int(f.Fd()), 0, int(fi.Size()),
|
||||
unix.PROT_READ, unix.MAP_SHARED)
|
||||
if err != nil {
|
||||
p.Abort(fmt.Errorf("mmap %s: %v", fileToPack.Filename, err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// prepare initial directory entry
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue