Skip to content

Commit

Permalink
Add API to trigger data disk move only (home-assistant#129)
Browse files Browse the repository at this point in the history
* Add API to trigger data disk move only

Add a new D-Bus API which allows to trigger the data disk move only.
This allows to handle the selection and partitioning from Supervisor
directly (via UDisks2 D-Bus API). Handling partitioning directly in
Supervisor should improve device detection/selection and allows for
better error handling.

* Drop return value from MarkDataMove

* Fix linter error
  • Loading branch information
agners authored Mar 15, 2023
1 parent 7bce7d6 commit a470aa2
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions datadisk/datadisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ type datadisk struct {
props *prop.Properties
}

func (d datadisk) MarkDataMove() *dbus.Error {
/* Move request marker for hassos-data.service */
fileName := "/mnt/overlay/move-data"
_, err := os.Stat(fileName)
if os.IsNotExist(err) {
file, err := os.Create(fileName)
if err != nil {
return dbus.MakeFailedError(err)
}
defer file.Close()
}

return nil
}

func (d datadisk) ChangeDevice(newDevice string) (bool, *dbus.Error) {
logging.Info.Printf("Request to change data disk to %s.", newDevice)

Expand All @@ -59,15 +74,9 @@ func (d datadisk) ChangeDevice(newDevice string) (bool, *dbus.Error) {
return false, dbus.MakeFailedError(err)
}

/* Move request marker for hassos-data.service */
fileName := "/mnt/overlay/move-data"
_, err = os.Stat(fileName)
if os.IsNotExist(err) {
file, err := os.Create(fileName)
if err != nil {
return false, dbus.MakeFailedError(err)
}
defer file.Close()
dbuserr := d.MarkDataMove()
if dbuserr != nil {
return false, dbuserr
}

return true, nil
Expand Down

0 comments on commit a470aa2

Please sign in to comment.