36 lines
687 B
Go
36 lines
687 B
Go
//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
|
|
}
|