Skip to content

Commit

Permalink
Merge pull request #39 from resin-os/fadvise-fix
Browse files Browse the repository at this point in the history
pkg/archive: sync files before issuing the fadvise syscall
  • Loading branch information
petrosagg authored Oct 13, 2017
2 parents eeead5b + bcabde6 commit c6df57f
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,17 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
file.Close()
return err
}

if err := file.Sync(); err != nil {
file.Close()
return err
}

if err := unix.Fadvise(int(file.Fd()), 0, 0, unix.FADV_DONTNEED); err != nil {
file.Close()
return err
}

file.Close()

case tar.TypeBlock, tar.TypeChar:
Expand Down Expand Up @@ -624,19 +635,6 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
}
}

if hdr.Typeflag == tar.TypeReg || hdr.Typeflag == tar.TypeRegA {
file, err := os.Open(path)
if err != nil {
file.Close()
return err
}
if err := unix.Fadvise(int(file.Fd()), 0, 0, unix.FADV_DONTNEED); err != nil {
file.Close()
return err
}
file.Close()
}

return nil
}

Expand Down

0 comments on commit c6df57f

Please sign in to comment.