mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-06-18 19:37:34 +00:00
It was added first to agent as it was needed for upgrade but if we are gonna reuse this to check for signature validity in random files, we better have it on sdk so we can use it both on agent and immucore and works exactly the same Signed-off-by: Itxaka <itxaka@kairos.io>
29 lines
676 B
Go
29 lines
676 B
Go
package utils
|
|
|
|
import (
|
|
sdkTypes "github.com/kairos-io/kairos-sdk/types"
|
|
"github.com/twpayne/go-vfs/v4"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
// permError returns an *os.PathError with Err syscall.EPERM.
|
|
func permError(op, path string) error {
|
|
return &os.PathError{
|
|
Op: op,
|
|
Path: path,
|
|
Err: syscall.EPERM,
|
|
}
|
|
}
|
|
|
|
// MkdirAll directory and all parents if not existing
|
|
func MkdirAll(fs sdkTypes.KairosFS, name string, mode os.FileMode) (err error) {
|
|
if _, isReadOnly := fs.(*vfs.ReadOnlyFS); isReadOnly {
|
|
return permError("mkdir", name)
|
|
}
|
|
if name, err = fs.RawPath(name); err != nil {
|
|
return &os.PathError{Op: "mkdir", Path: name, Err: err}
|
|
}
|
|
return os.MkdirAll(name, mode)
|
|
}
|