From: Matt Joiner Date: Thu, 8 Feb 2018 12:57:35 +0000 (+1100) Subject: There was no error for missing file, and no way to close the mmap returned from iplis... X-Git-Tag: v1.0.0~190 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=1f81f57b9ca9534a41e45f08f577f98bfbca5664;p=btrtrc.git 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. --- diff --git a/iplist/packed.go b/iplist/packed.go index 427e5572..143bca03 100644 --- a/iplist/packed.go +++ b/iplist/packed.go @@ -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) { +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 os.IsNotExist(err) { - err = nil - return - } 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 }