Add support to --chown flag to ADD command

This commit is contained in:
Dani Raznikov
2020-03-14 16:24:40 +02:00
parent 9cfb196d02
commit c136f886a9
9 changed files with 109 additions and 78 deletions
+20
View File
@@ -35,6 +35,11 @@ import (
"github.com/sirupsen/logrus"
)
// for testing
var (
getUIDAndGID = GetUIDAndGIDFromString
)
const (
pathSeparator = "/"
)
@@ -335,6 +340,21 @@ Loop:
return nil
}
func GetUserGroup(chownStr string, env []string) (int64, int64, error) {
if chownStr == "" {
return DoNotChangeUID, DoNotChangeGID, nil
}
chown, err := ResolveEnvironmentReplacement(chownStr, env, false)
if err != nil {
return -1, -1, err
}
uid32, gid32, err := getUIDAndGID(chown, true)
if err != nil {
return -1, -1, err
}
return int64(uid32), int64(gid32), nil
}
// Extract user and group id from a string formatted 'user:group'.
// If fallbackToUID is set, the gid is equal to uid if the group is not specified
// otherwise gid is set to zero.