feat: Added --chmod for ADD and COPY command. Fixes #2850 (#3119)

This commit is contained in:
Matthias Schneider
2024-04-22 09:28:37 -07:00
committed by GitHub
parent 87e646a0b3
commit a9062b97f7
10 changed files with 227 additions and 95 deletions
+19
View File
@@ -18,6 +18,7 @@ package util
import (
"fmt"
"io/fs"
"net/url"
"os"
"os/user"
@@ -370,6 +371,24 @@ func GetUserGroup(chownStr string, env []string) (int64, int64, error) {
return int64(uid32), int64(gid32), nil
}
func GetChmod(chmodStr string, env []string) (chmod fs.FileMode, useDefault bool, err error) {
if chmodStr == "" {
return fs.FileMode(0o600), true, nil
}
chmodStr, err = ResolveEnvironmentReplacement(chmodStr, env, false)
if err != nil {
return 0, false, err
}
mode, err := strconv.ParseUint(chmodStr, 8, 32)
if err != nil {
return 0, false, errors.Wrap(err, "parsing value from chmod")
}
chmod = fs.FileMode(mode)
return
}
// Extract user and group id from a string formatted 'user:group'.
// UserID and GroupID don't need to be present on the system.
func getUIDAndGIDFromString(userGroupString string) (uint32, uint32, error) {