Fix permissions on ADD/COPY
Fix a regression introduced in PR#9467 when a single file was added or copied. Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com> Upstream-commit: cfc24769a26e825e4267cbfdd59af807e27508b9 Component: engine
This commit is contained in:
@ -660,11 +660,19 @@ func copyAsDirectory(source, destination string) error {
|
||||
}
|
||||
|
||||
func fixPermissions(source, destination string, uid, gid int) error {
|
||||
// The copied root permission should not be changed for previously existing
|
||||
// directories.
|
||||
s, err := os.Stat(destination)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
fixRootPermission := (err != nil) || !s.IsDir()
|
||||
|
||||
// We Walk on the source rather than on the destination because we don't
|
||||
// want to change permissions on things we haven't created or modified.
|
||||
return filepath.Walk(source, func(fullpath string, info os.FileInfo, err error) error {
|
||||
// Do not alter the walk root itself as it potentially existed before.
|
||||
if source == fullpath {
|
||||
if !fixRootPermission && (source == fullpath) {
|
||||
return nil
|
||||
}
|
||||
// Path is prefixed by source: substitute with destination instead.
|
||||
|
||||
Reference in New Issue
Block a user