mirror of
https://github.com/clearlinux/docker.git
synced 2026-10-04 15:58:39 +00:00
Merge pull request #5116 from LK4D4/chown_only_on_content_#5110
This commit is contained in:
+32
-6
@@ -397,9 +397,10 @@ func (b *buildFile) checkPathForAddition(orig string) error {
|
||||
|
||||
func (b *buildFile) addContext(container *daemon.Container, orig, dest string, remote bool) error {
|
||||
var (
|
||||
err error
|
||||
origPath = path.Join(b.contextPath, orig)
|
||||
destPath = path.Join(container.RootfsPath(), dest)
|
||||
err error
|
||||
destExists = true
|
||||
origPath = path.Join(b.contextPath, orig)
|
||||
destPath = path.Join(container.RootfsPath(), dest)
|
||||
)
|
||||
|
||||
if destPath != container.RootfsPath() {
|
||||
@@ -413,6 +414,14 @@ func (b *buildFile) addContext(container *daemon.Container, orig, dest string, r
|
||||
if strings.HasSuffix(dest, "/") {
|
||||
destPath = destPath + "/"
|
||||
}
|
||||
destStat, err := os.Stat(destPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
destExists = false
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
fi, err := os.Stat(origPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@@ -434,8 +443,20 @@ func (b *buildFile) addContext(container *daemon.Container, orig, dest string, r
|
||||
if err := archive.CopyWithTar(origPath, destPath); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := chownR(destPath, 0, 0); err != nil {
|
||||
return err
|
||||
if destExists {
|
||||
files, err := ioutil.ReadDir(origPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, file := range files {
|
||||
if err := chownR(filepath.Join(destPath, file.Name()), 0, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err := chownR(destPath, 0, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -467,7 +488,12 @@ func (b *buildFile) addContext(container *daemon.Container, orig, dest string, r
|
||||
return err
|
||||
}
|
||||
|
||||
if err := chownR(destPath, 0, 0); err != nil {
|
||||
resPath := destPath
|
||||
if destExists && destStat.IsDir() {
|
||||
resPath = path.Join(destPath, path.Base(origPath))
|
||||
}
|
||||
|
||||
if err := chownR(resPath, 0, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user