Fixes #3979
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
| ... | ... |
@@ -5,4 +5,5 @@ RUN touch /exists |
| 5 | 5 |
RUN chown dockerio.dockerio /exists |
| 6 | 6 |
ADD test_file / |
| 7 | 7 |
RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 8 |
+RUN [ $(ls -l /test_file | awk '{print $1}') = '-rwxr-xr-x' ]
|
|
| 8 | 9 |
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
|
| ... | ... |
@@ -5,5 +5,7 @@ RUN touch /exists |
| 5 | 5 |
RUN chown dockerio.dockerio exists |
| 6 | 6 |
ADD test_dir /test_dir |
| 7 | 7 |
RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ]
|
| 8 |
+RUN [ $(ls -l / | grep test_dir | awk '{print $1}') = 'drwxr-xr-x' ]
|
|
| 8 | 9 |
RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
|
| 10 |
+RUN [ $(ls -l /test_dir/test_file | awk '{print $1}') = '-rwxr-xr-x' ]
|
|
| 9 | 11 |
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
|
| ... | ... |
@@ -431,9 +431,12 @@ func (b *buildFile) addContext(container *daemon.Container, orig, dest string, r |
| 431 | 431 |
return err |
| 432 | 432 |
} |
| 433 | 433 |
|
| 434 |
- chownR := func(destPath string, uid, gid int) error {
|
|
| 434 |
+ fixPermsR := func(destPath string, uid, gid int) error {
|
|
| 435 | 435 |
return filepath.Walk(destPath, func(path string, info os.FileInfo, err error) error {
|
| 436 |
- if err := os.Lchown(path, uid, gid); err != nil {
|
|
| 436 |
+ if err := os.Lchown(path, uid, gid); err != nil && !os.IsNotExist(err) {
|
|
| 437 |
+ return err |
|
| 438 |
+ } |
|
| 439 |
+ if err := os.Chmod(path, 0755); err != nil && !os.IsNotExist(err) {
|
|
| 437 | 440 |
return err |
| 438 | 441 |
} |
| 439 | 442 |
return nil |
| ... | ... |
@@ -450,12 +453,12 @@ func (b *buildFile) addContext(container *daemon.Container, orig, dest string, r |
| 450 | 450 |
return err |
| 451 | 451 |
} |
| 452 | 452 |
for _, file := range files {
|
| 453 |
- if err := chownR(filepath.Join(destPath, file.Name()), 0, 0); err != nil {
|
|
| 453 |
+ if err := fixPermsR(filepath.Join(destPath, file.Name()), 0, 0); err != nil {
|
|
| 454 | 454 |
return err |
| 455 | 455 |
} |
| 456 | 456 |
} |
| 457 | 457 |
} else {
|
| 458 |
- if err := chownR(destPath, 0, 0); err != nil {
|
|
| 458 |
+ if err := fixPermsR(destPath, 0, 0); err != nil {
|
|
| 459 | 459 |
return err |
| 460 | 460 |
} |
| 461 | 461 |
} |
| ... | ... |
@@ -494,7 +497,7 @@ func (b *buildFile) addContext(container *daemon.Container, orig, dest string, r |
| 494 | 494 |
resPath = path.Join(destPath, path.Base(origPath)) |
| 495 | 495 |
} |
| 496 | 496 |
|
| 497 |
- if err := chownR(resPath, 0, 0); err != nil {
|
|
| 497 |
+ if err := fixPermsR(resPath, 0, 0); err != nil {
|
|
| 498 | 498 |
return err |
| 499 | 499 |
} |
| 500 | 500 |
return nil |