Merge pull request #462 from sgotti/tarrestoreuidgid

tar: restore entry's uid and gid.
This commit is contained in:
Vito Caputo
2015-02-04 12:45:27 -08:00
2 changed files with 10 additions and 0 deletions
+7
View File
@@ -149,6 +149,13 @@ func ExtractFile(tr *tar.Reader, hdr *tar.Header, dir string, overwrite bool) er
return fmt.Errorf("unsupported type: %v", typ)
}
// TODO(sgotti). lchown(2) says that, depending on the linux kernel
// version, chown can change the file mode also if executed as root.
// To be sure, Should we call os.Chmod after it?
if err := os.Lchown(p, hdr.Uid, hdr.Gid); err != nil {
return err
}
return nil
}
+3
View File
@@ -45,6 +45,9 @@ func newTestTar(entries []*testTarEntry) (string, error) {
entry.header.Mode = 0644
}
}
// Add calling user uid and gid or tests will fail
entry.header.Uid = os.Getuid()
entry.header.Gid = os.Getgid()
if err := tw.WriteHeader(entry.header); err != nil {
return "", err
}