There was no error for missing file, and no way to close the mmap returned from iplist.MmapPacked

The function is also renamed due to the changed behaviour.
This commit is contained in:
Matt Joiner 2018-02-08 23:57:35 +11:00
parent fadbd68d99
commit 1f81f57b9c
1 changed files with 17 additions and 7 deletions

View File

@ -114,12 +114,20 @@ func (pil PackedIPList) Lookup(ip net.IP) (r Range, ok bool) {
return lookup(pil.getFirst, pil.getRange, pil.len(), ip4)
}
func MMapPacked(filename string) (ret Ranger, err error) {
f, err := os.Open(filename)
if os.IsNotExist(err) {
err = nil
return
type closerFunc func() error
func (me closerFunc) Close() error {
return me()
}
func MMapPackedFile(filename string) (
ret interface {
Ranger
io.Closer
},
err error,
) {
f, err := os.Open(filename)
if err != nil {
return
}
@ -128,7 +136,9 @@ func MMapPacked(filename string) (ret Ranger, err error) {
if err != nil {
return
}
// TODO: Need a destructor that unmaps this.
ret = NewFromPacked(mm)
ret = struct {
Ranger
io.Closer
}{NewFromPacked(mm), closerFunc(mm.Unmap)}
return
}