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 {
change := c.changesMap[key.(string)]
if change == nil {
c.l.Error().Str("key", key.(string)).Msg("fileChange not found")
continue
}
if !initial {
change.ResetActionResolution()
}

View File

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