From a8f0f1be031e0b7968b5603571e14ef515e1ebd3 Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Mon, 26 Jan 2015 17:25:20 -0500 Subject: [PATCH] Make sure we close the open files each time. --- appended.go | 3 ++- box.go | 2 +- virtual.go | 6 +++--- walk.go | 4 +++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/appended.go b/appended.go index 1b781cb..0cfba30 100644 --- a/appended.go +++ b/appended.go @@ -35,10 +35,11 @@ func init() { if err != nil { return // not apended or cant find self executable } - rd, err := zipexe.Open(thisFile) + closer, rd, err := zipexe.Open(thisFile) if err != nil { return // not apended } + defer closer.Close() for _, f := range rd.File { // get box and file name from f.Name diff --git a/box.go b/box.go index 7c57aec..23541ab 100644 --- a/box.go +++ b/box.go @@ -267,11 +267,11 @@ func (b *Box) Bytes(name string) ([]byte, error) { if err != nil { return nil, err } + defer rc.Close() cpy, err := ioutil.ReadAll(rc) if err != nil { return nil, err } - rc.Close() return cpy, nil } diff --git a/virtual.go b/virtual.go index 3c4e14c..e208fb4 100644 --- a/virtual.go +++ b/virtual.go @@ -131,9 +131,9 @@ func (vf *virtualFile) seek(offset int64, whence int) (int64, error) { return vf.offset, nil } -// vritualDir is a 'stateful' virtual directory. -// vritualDir wraps an *EmbeddedDir for a call to Box.Open() and virtualizes 'closing'. -// vritualDir is only internally visible and should be exposed through rice.File +// virtualDir is a 'stateful' virtual directory. +// virtualDir wraps an *EmbeddedDir for a call to Box.Open() and virtualizes 'closing'. +// virtualDir is only internally visible and should be exposed through rice.File type virtualDir struct { *embedded.EmbeddedDir offset int // readdir positon on the directory diff --git a/walk.go b/walk.go index 827f4ff..3042aea 100644 --- a/walk.go +++ b/walk.go @@ -15,6 +15,7 @@ func (b *Box) Walk(path string, walkFn filepath.WalkFunc) error { if err != nil { return err } + defer pathFile.Close() pathInfo, err := pathFile.Stat() if err != nil { @@ -64,6 +65,7 @@ func (b *Box) walk(path string, info os.FileInfo, walkFn filepath.WalkFunc) erro if err != nil { return err } + defer fileObject.Close() fileInfo, err := fileObject.Stat() if err != nil { @@ -92,6 +94,7 @@ func (b *Box) readDirNames(path string) ([]string, error) { if err != nil { return nil, err } + defer f.Close() stat, err := f.Stat() if err != nil { @@ -103,7 +106,6 @@ func (b *Box) readDirNames(path string) ([]string, error) { } infos, err := f.Readdir(0) - f.Close() if err != nil { return nil, err }