Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

Commit

Permalink
Remove files from lower layer before writing
Browse files Browse the repository at this point in the history
If the lower layer contained a symlink, the write logic would end
up writing to the symlinked file. This change also allows an upper
layer to replace a paths of one type (dir, file symlink) with another.

Fixes #6
  • Loading branch information
Vishvananda Ishaya Abrams committed Jul 20, 2017
1 parent b910e73 commit d4226a0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,13 @@ func extractLayer(layer *Layer, outDir string) error {
}

path := filepath.Join(outDir, clean)
info, err := os.Lstat(path)
// remove any existing file at the location unless both locations are a dir
if err == nil && !(hdr.Typeflag == tar.TypeDir && info.IsDir()) {
if err := os.RemoveAll(path); err != nil {
logrus.Warnf("Failed to remove %s", path)
}
}
switch hdr.Typeflag {
case tar.TypeDir:
os.MkdirAll(path, 0755)
Expand Down

0 comments on commit d4226a0

Please sign in to comment.