-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
Bumps [github.com/containers/image/v5](https://github.com/containers/image) from 5.10.2 to 5.10.3. - [Release notes](https://github.com/containers/image/releases) - [Commits](containers/image@v5.10.2...v5.10.3) Signed-off-by: dependabot-preview[bot] <[email protected]> Signed-off-by: Daniel J Walsh <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// +build !windows | ||
|
||
package chown | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"syscall" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// ChangeHostPathOwnership changes the uid and gid ownership of a directory or file within the host. | ||
// This is used by the volume U flag to change source volumes ownership | ||
func ChangeHostPathOwnership(path string, recursive bool, uid, gid int) error { | ||
// Validate if host path can be chowned | ||
isDangerous, err := DangerousHostPath(path) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to validate if host path is dangerous") | ||
} | ||
|
||
if isDangerous { | ||
return errors.Errorf("chowning host path %q is not allowed. You can manually `chown -R %d:%d %s`", path, uid, gid, path) | ||
} | ||
|
||
// Chown host path | ||
if recursive { | ||
err := filepath.Walk(path, func(filePath string, f os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Get current ownership | ||
currentUID := int(f.Sys().(*syscall.Stat_t).Uid) | ||
currentGID := int(f.Sys().(*syscall.Stat_t).Gid) | ||
|
||
if uid != currentUID || gid != currentGID { | ||
return os.Lchown(filePath, uid, gid) | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return errors.Wrapf(err, "failed to chown recursively host path") | ||
} | ||
} else { | ||
// Get host path info | ||
f, err := os.Lstat(path) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to get host path information") | ||
} | ||
|
||
// Get current ownership | ||
currentUID := int(f.Sys().(*syscall.Stat_t).Uid) | ||
currentGID := int(f.Sys().(*syscall.Stat_t).Gid) | ||
|
||
if uid != currentUID || gid != currentGID { | ||
if err := os.Lchown(path, uid, gid); err != nil { | ||
return errors.Wrapf(err, "failed to chown host path") | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package chown | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// ChangeHostPathOwnership changes the uid and gid ownership of a directory or file within the host. | ||
// This is used by the volume U flag to change source volumes ownership | ||
func ChangeHostPathOwnership(path string, recursive bool, uid, gid int) error { | ||
return errors.Errorf("windows not supported") | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.