1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-22 16:25:38 +00:00

tar: explicitly close files after populateTree

Files don't close properly when `defer`ing inside
a for loop, since the surrounding function is still
iterating in a for loop. To fix this, just close the files
explicitly after `populateTree()` in `readHeaders()`

Signed-off-by: Stephen Chung <schung@redhat.com>
This commit is contained in:
Stephen Chung 2016-07-25 20:04:55 -04:00
parent b0c1606133
commit 767d4bbb4b

5
tar.go
View file

@ -93,9 +93,6 @@ func (ts *tarStream) readHeaders() {
ts.pipeReader.CloseWithError(err) ts.pipeReader.CloseWithError(err)
return return
} }
defer tmpFile.Close()
defer os.Remove(tmpFile.Name())
// Alright, it's either file or directory // Alright, it's either file or directory
encodedName, err := Vis(filepath.Base(hdr.Name)) encodedName, err := Vis(filepath.Base(hdr.Name))
if err != nil { if err != nil {
@ -175,6 +172,8 @@ func (ts *tarStream) readHeaders() {
} }
} }
populateTree(&root, &e, hdr, ts) populateTree(&root, &e, hdr, ts)
tmpFile.Close()
os.Remove(tmpFile.Name())
} }
} }