Writes and verify image
This commit is contained in:
35
clitools/pkg/controller/osimage/verify_safe.go
Normal file
35
clitools/pkg/controller/osimage/verify_safe.go
Normal file
@@ -0,0 +1,35 @@
|
||||
//go:build !dev
|
||||
|
||||
package osimage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func CheckTargetSafe(targetPath string, expectedRawSize int64) error {
|
||||
|
||||
if !strings.HasPrefix(targetPath, "/dev/") {
|
||||
return fmt.Errorf("target must be a device path under /dev")
|
||||
}
|
||||
|
||||
st, err := os.Stat(targetPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("stat target: %w", err)
|
||||
}
|
||||
|
||||
mode := st.Mode()
|
||||
if mode&os.ModeDevice == 0 {
|
||||
return fmt.Errorf("target is not a device")
|
||||
}
|
||||
|
||||
// TODO: Add stronger checks
|
||||
// - EnsureNotMounted(targetPath)
|
||||
// - EnsureNotCurrentRoot(targetPath)
|
||||
// - EnsurePartitionNotWholeDisk(targetPath)
|
||||
// - EnsureCapacity(targetPath, expectedRawSize)
|
||||
|
||||
_ = expectedRawSize
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user