mirror of
https://github.com/containers/podman.git
synced 2025-12-01 10:38:05 +08:00
The change in healthcheck_run_test.go, depends on the containers/image change: commit b6afa8ca7b324aca8fd5a7b5b206fc05c0c04874 Author: Mikhail Sokolov <msokolov@evolution.com> Date: Fri Mar 15 13:37:44 2024 +0200 Add support for Docker HealthConfig.StartInterval (v25.0.0+) Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package umask
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/containers/storage/pkg/fileutils"
|
|
)
|
|
|
|
// MkdirAllIgnoreUmask creates a directory by ignoring the currently set umask.
|
|
func MkdirAllIgnoreUmask(dir string, mode os.FileMode) error {
|
|
parent := dir
|
|
dirs := []string{}
|
|
|
|
// Find all parent directories which would have been created by MkdirAll
|
|
for {
|
|
if err := fileutils.Exists(parent); err == nil {
|
|
break
|
|
} else if !os.IsNotExist(err) {
|
|
return fmt.Errorf("cannot stat %s: %w", dir, err)
|
|
}
|
|
|
|
dirs = append(dirs, parent)
|
|
newParent := filepath.Dir(parent)
|
|
|
|
// Only possible if the root paths are not existing, which would be odd
|
|
if parent == newParent {
|
|
break
|
|
}
|
|
|
|
parent = newParent
|
|
}
|
|
|
|
if err := os.MkdirAll(dir, mode); err != nil {
|
|
return fmt.Errorf("create directory %s: %w", dir, err)
|
|
}
|
|
|
|
for _, d := range dirs {
|
|
if err := os.Chmod(d, mode); err != nil {
|
|
return fmt.Errorf("chmod directory %s: %w", d, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// WriteFileIgnoreUmask write the provided data to the path by ignoring the
|
|
// currently set umask.
|
|
func WriteFileIgnoreUmask(path string, data []byte, mode os.FileMode) error {
|
|
if err := os.WriteFile(path, data, mode); err != nil {
|
|
return fmt.Errorf("write file: %w", err)
|
|
}
|
|
|
|
if err := os.Chmod(path, mode); err != nil {
|
|
return fmt.Errorf("chmod file: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|