Skip to content

Commit

Permalink
Set ownership to unpacked entries
Browse files Browse the repository at this point in the history
Signed-off-by: George Lestaris <glestaris@gmail.com>
  • Loading branch information
glestaris committed Sep 15, 2016
1 parent 853746e commit ea4e2ea
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions image/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ loop:
if err2 := os.MkdirAll(path, info.Mode()); err2 != nil {
return errors.Wrap(err2, "error creating directory")
}

if os.Getuid() == 0 {
if err2 := os.Chown(path, hdr.Uid, hdr.Gid); err2 != nil {
return errors.Wrap(err2, "error chowing directory")
}
}
}

case tar.TypeReg, tar.TypeRegA:
Expand All @@ -192,6 +198,12 @@ loop:
return errors.Wrap(err, "unable to open file")
}

if os.Getuid() == 0 {
if err := os.Chown(path, hdr.Uid, hdr.Gid); err != nil {
return errors.Wrap(err, "error chowing file")
}
}

if _, err := io.Copy(f, tr); err != nil {
f.Close()
return errors.Wrap(err, "unable to copy")
Expand Down Expand Up @@ -219,6 +231,13 @@ loop:
if err := os.Symlink(hdr.Linkname, path); err != nil {
return err
}

if os.Getuid() == 0 {
if err := os.Lchown(path, hdr.Uid, hdr.Gid); err != nil {
return errors.Wrap(err, "error chowing symlink")
}
}

case tar.TypeXGlobalHeader:
return nil
}
Expand Down

0 comments on commit ea4e2ea

Please sign in to comment.