fix(usbgadget): do not panic if a change isn't found

This commit is contained in:
Siyuan Miao 2025-05-20 00:19:42 +02:00
parent b4dd4961fc
commit c4782f28dc
2 changed files with 16 additions and 10 deletions

View File

@ -48,6 +48,11 @@ func (c *ChangeSetResolver) doResolveChanges(initial bool) error {
for _, key := range c.orderedChanges { for _, key := range c.orderedChanges {
change := c.changesMap[key.(string)] change := c.changesMap[key.(string)]
if change == nil {
c.l.Error().Str("key", key.(string)).Msg("fileChange not found")
continue
}
if !initial { if !initial {
change.ResetActionResolution() change.ResetActionResolution()
} }

View File

@ -177,12 +177,7 @@ func (u *UsbGadget) Init() error {
u.udc = udcs[0] u.udc = udcs[0]
err := u.WithTransaction(func() error { err := u.configureUsbGadget()
u.tx.MountConfigFS()
u.tx.CreateConfigPath()
u.tx.WriteGadgetConfig()
return nil
})
if err != nil { if err != nil {
return u.logError("unable to initialize USB stack", err) return u.logError("unable to initialize USB stack", err)
} }
@ -196,13 +191,19 @@ func (u *UsbGadget) UpdateGadgetConfig() error {
u.loadGadgetConfig() u.loadGadgetConfig()
err := u.WithTransaction(func() error { err := u.configureUsbGadget()
u.tx.WriteGadgetConfig()
return nil
})
if err != nil { if err != nil {
return u.logError("unable to update gadget config", err) return u.logError("unable to update gadget config", err)
} }
return nil return nil
} }
func (u *UsbGadget) configureUsbGadget() error {
return u.WithTransaction(func() error {
u.tx.MountConfigFS()
u.tx.CreateConfigPath()
u.tx.WriteGadgetConfig()
return nil
})
}