kairos-sdk/utils/fs.go
Itxaka a0c7d13520
Port signature utils to sdk from agent (#117)
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>
2024-06-04 08:31:00 +02:00

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)
}