Skip to content

Commit

Permalink
fixed bug where files were not being create if they were in a path th…
Browse files Browse the repository at this point in the history
…at didn't exist
  • Loading branch information
ChrisMcKenzie committed Nov 11, 2015
1 parent 2a3d13c commit a69d776
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions installer/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,13 @@ func (i TarInstaller) Install(dest string, fr io.Reader) (count int, err error)
if err == io.EOF {
// end of tar archive
err = nil
break
}
if err != nil {
return
}
path := filepath.Join(dest, hdr.Name)
info := hdr.FileInfo()

if info.IsDir() {
if err = os.MkdirAll(path, info.Mode()); err != nil {
return
}
continue
}

var file *os.File
file, err = os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode())
if err != nil {
return
}
defer file.Close()

_, err = io.Copy(file, tr)
if err != nil {
if err = writePath(hdr, tr, dest); err != nil {
return
}
count++
Expand All @@ -69,3 +52,33 @@ func (i TarInstaller) Install(dest string, fr io.Reader) (count int, err error)
defer cleanup(dest, err)
return
}

func writePath(hdr *tar.Header, tr *tar.Reader, dest string) (err error) {
path := filepath.Join(dest, hdr.Name)
info := hdr.FileInfo()

if info.IsDir() {
if err = os.MkdirAll(path, info.Mode()); err != nil {
return
}
return
}

var file *os.File
dirPath := filepath.Dir(path)
if err = os.MkdirAll(dirPath, os.ModePerm); err != nil {
return
}
file, err = os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode())
if err != nil {
return
}
defer file.Close()

_, err = io.Copy(file, tr)
if err != nil {
return
}

return nil
}

0 comments on commit a69d776

Please sign in to comment.