Files
kaniko/vendor/github.com/otiai10/copy/permission_control.go
T
dependabot[bot] 74b2b6c9ef chore(deps): bump github.com/otiai10/copy from 1.7.0 to 1.11.0 (#2523)
Bumps [github.com/otiai10/copy](https://github.com/otiai10/copy) from 1.7.0 to 1.11.0.
- [Release notes](https://github.com/otiai10/copy/releases)
- [Commits](https://github.com/otiai10/copy/compare/v1.7.0...v1.11.0)

---
updated-dependencies:
- dependency-name: github.com/otiai10/copy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-23 16:13:34 -07:00

49 lines
1.4 KiB
Go

package copy
import (
"os"
)
const (
// tmpPermissionForDirectory makes the destination directory writable,
// so that stuff can be copied recursively even if any original directory is NOT writable.
// See https://github.com/otiai10/copy/pull/9 for more information.
tmpPermissionForDirectory = os.FileMode(0755)
)
type PermissionControlFunc func(srcinfo fileInfo, dest string) (chmodfunc func(*error), err error)
var (
AddPermission = func(perm os.FileMode) PermissionControlFunc {
return func(srcinfo fileInfo, dest string) (func(*error), error) {
orig := srcinfo.Mode()
if srcinfo.IsDir() {
if err := os.MkdirAll(dest, tmpPermissionForDirectory); err != nil {
return func(*error) {}, err
}
}
return func(err *error) {
chmod(dest, orig|perm, err)
}, nil
}
}
PerservePermission PermissionControlFunc = AddPermission(0)
DoNothing PermissionControlFunc = func(srcinfo fileInfo, dest string) (func(*error), error) {
if srcinfo.IsDir() {
if err := os.MkdirAll(dest, srcinfo.Mode()); err != nil {
return func(*error) {}, err
}
}
return func(*error) {}, nil
}
)
// chmod ANYHOW changes file mode,
// with asiging error raised during Chmod,
// BUT respecting the error already reported.
func chmod(dir string, mode os.FileMode, reported *error) {
if err := os.Chmod(dir, mode); *reported == nil {
*reported = err
}
}