Move logic to check if deviceinfo file exists to pkgs/deviceinfo (MR 37)

This is mostly a preparatory commit to later be able to read the
deviceinfo from multiple places. It has a bit better encapsulation,
and makes the functions methods, so that they can update deviceinfo
file in-place.
This commit is contained in:
Pablo Correa Gómez
2023-05-29 23:06:31 +02:00
committed by Clayton Craft
parent b2cdfe9da4
commit c87b926a53
3 changed files with 21 additions and 22 deletions

View File

@@ -49,19 +49,9 @@ func main() {
log.Default().SetFlags(log.Lmicroseconds)
deviceinfoFile := "/etc/deviceinfo"
if exists, err := misc.Exists(deviceinfoFile); !exists {
log.Printf("NOTE: %q not found, this file is required by mkinitfs.\n", deviceinfoFile)
return
} else if err != nil {
retCode = 1
log.Printf("received unexpected error when getting status for %q: %s", deviceinfoFile, err)
return
}
devinfo, err := deviceinfo.ReadDeviceinfo(deviceinfoFile)
if err != nil {
log.Println(err)
var devinfo deviceinfo.DeviceInfo
if err := devinfo.ReadDeviceinfo("/etc/deviceinfo"); err != nil {
log.Println("Error reading deviceinfo:", err)
retCode = 1
return
}