Merge pull request #4193 from creack/3964-add_tar-fix

Fix remote tar ADD behavior
This commit is contained in:
Michael Crosby 2014-02-17 20:37:42 -05:00
commit 8f11a1a61f
1 changed files with 11 additions and 7 deletions

View File

@ -355,7 +355,7 @@ func (b *buildFile) checkPathForAddition(orig string) error {
return nil return nil
} }
func (b *buildFile) addContext(container *Container, orig, dest string) error { func (b *buildFile) addContext(container *Container, orig, dest string, remote bool) error {
var ( var (
origPath = path.Join(b.contextPath, orig) origPath = path.Join(b.contextPath, orig)
destPath = path.Join(container.BasefsPath(), dest) destPath = path.Join(container.BasefsPath(), dest)
@ -388,11 +388,14 @@ func (b *buildFile) addContext(container *Container, orig, dest string) error {
tarDest = filepath.Dir(destPath) tarDest = filepath.Dir(destPath)
} }
// If we are adding a remote file, do not try to untar it
if !remote {
// try to successfully untar the orig // try to successfully untar the orig
if err := archive.UntarPath(origPath, tarDest); err == nil { if err := archive.UntarPath(origPath, tarDest); err == nil {
return nil return nil
} }
utils.Debugf("Couldn't untar %s to %s: %s", origPath, destPath, err) utils.Debugf("Couldn't untar %s to %s: %s", origPath, destPath, err)
}
// If that fails, just copy it as a regular file // If that fails, just copy it as a regular file
// but do not use all the magic path handling for the tar path // but do not use all the magic path handling for the tar path
@ -428,14 +431,15 @@ func (b *buildFile) CmdAdd(args string) error {
b.config.Cmd = []string{"/bin/sh", "-c", fmt.Sprintf("#(nop) ADD %s in %s", orig, dest)} b.config.Cmd = []string{"/bin/sh", "-c", fmt.Sprintf("#(nop) ADD %s in %s", orig, dest)}
b.config.Image = b.image b.config.Image = b.image
// FIXME: do we really need this?
var ( var (
origPath = orig origPath = orig
destPath = dest destPath = dest
remoteHash string remoteHash string
isRemote bool
) )
if utils.IsURL(orig) { if utils.IsURL(orig) {
isRemote = true
resp, err := utils.Download(orig) resp, err := utils.Download(orig)
if err != nil { if err != nil {
return err return err
@ -545,7 +549,7 @@ func (b *buildFile) CmdAdd(args string) error {
} }
defer container.Unmount() defer container.Unmount()
if err := b.addContext(container, origPath, destPath); err != nil { if err := b.addContext(container, origPath, destPath, isRemote); err != nil {
return err return err
} }