1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #3971 from creack/fix_add_ownership

Change ownership to root for ADD file/directory
This commit is contained in:
Michael Crosby 2014-04-02 12:22:09 -07:00
commit 9cc7eb4ab3

View file

@ -419,10 +419,22 @@ func (b *buildFile) addContext(container *runtime.Container, orig, dest string,
return err
}
chownR := func(destPath string, uid, gid int) error {
return filepath.Walk(destPath, func(path string, info os.FileInfo, err error) error {
if err := os.Lchown(path, uid, gid); err != nil {
return err
}
return nil
})
}
if fi.IsDir() {
if err := archive.CopyWithTar(origPath, destPath); err != nil {
return err
}
if err := chownR(destPath, 0, 0); err != nil {
return err
}
return nil
}
@ -452,6 +464,10 @@ func (b *buildFile) addContext(container *runtime.Container, orig, dest string,
if err := archive.CopyWithTar(origPath, destPath); err != nil {
return err
}
if err := chownR(destPath, 0, 0); err != nil {
return err
}
return nil
}
@ -486,28 +502,36 @@ func (b *buildFile) CmdAdd(args string) error {
)
if utils.IsURL(orig) {
// Initiate the download
isRemote = true
resp, err := utils.Download(orig)
if err != nil {
return err
}
// Create a tmp dir
tmpDirName, err := ioutil.TempDir(b.contextPath, "docker-remote")
if err != nil {
return err
}
// Create a tmp file within our tmp dir
tmpFileName := path.Join(tmpDirName, "tmp")
tmpFile, err := os.OpenFile(tmpFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
if err != nil {
return err
}
defer os.RemoveAll(tmpDirName)
if _, err = io.Copy(tmpFile, resp.Body); err != nil {
// Download and dump result to tmp file
if _, err := io.Copy(tmpFile, resp.Body); err != nil {
tmpFile.Close()
return err
}
origPath = path.Join(filepath.Base(tmpDirName), filepath.Base(tmpFileName))
tmpFile.Close()
origPath = path.Join(filepath.Base(tmpDirName), filepath.Base(tmpFileName))
// Process the checksum
r, err := archive.Tar(tmpFileName, archive.Uncompressed)
if err != nil {