Skip to content

Commit

Permalink
Make sure we close the open files each time.
Browse files Browse the repository at this point in the history
  • Loading branch information
abourget committed Jan 26, 2015
1 parent 35d74f1 commit a8f0f1b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion appended.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion box.go
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions virtual.go
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion walk.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit a8f0f1b

Please sign in to comment.