Skip to content

Commit

Permalink
Change ownership to root for ADD file/directory
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)
  • Loading branch information
creack committed Apr 1, 2014
1 parent 7462cc6 commit 026aebd
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions server/buildfile.go
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 026aebd

Please sign in to comment.