forked from Silverfish/proton-bridge
GODT-2223: Fix mutex double lock
This commit is contained in:
committed by
Leander Beernaert
parent
59745e6fb6
commit
faf28a6d4e
@ -211,43 +211,41 @@ func (conn *imapConnector) updateLabel(ctx context.Context, labelID imap.Mailbox
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (conn *imapConnector) updateFolder(ctx context.Context, labelID imap.MailboxID, name []string) error {
|
func (conn *imapConnector) updateFolder(ctx context.Context, labelID imap.MailboxID, name []string) error {
|
||||||
return safe.LockRet(func() error {
|
var parentID string
|
||||||
var parentID string
|
|
||||||
|
|
||||||
if len(name) > 1 {
|
if len(name) > 1 {
|
||||||
for _, label := range conn.apiLabels {
|
for _, label := range conn.apiLabels {
|
||||||
if !slices.Equal(label.Path, name[:len(name)-1]) {
|
if !slices.Equal(label.Path, name[:len(name)-1]) {
|
||||||
continue
|
continue
|
||||||
}
|
|
||||||
|
|
||||||
parentID = label.ID
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if parentID == "" {
|
parentID = label.ID
|
||||||
return fmt.Errorf("parent folder %q does not exist", name[:len(name)-1])
|
|
||||||
}
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
label, err := conn.client.GetLabel(ctx, string(labelID), proton.LabelTypeFolder)
|
if parentID == "" {
|
||||||
if err != nil {
|
return fmt.Errorf("parent folder %q does not exist", name[:len(name)-1])
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update, err := conn.client.UpdateLabel(ctx, string(labelID), proton.UpdateLabelReq{
|
label, err := conn.client.GetLabel(ctx, string(labelID), proton.LabelTypeFolder)
|
||||||
Name: name[len(name)-1],
|
if err != nil {
|
||||||
Color: label.Color,
|
return err
|
||||||
ParentID: parentID,
|
}
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
conn.apiLabels[label.ID] = update
|
update, err := conn.client.UpdateLabel(ctx, string(labelID), proton.UpdateLabelReq{
|
||||||
|
Name: name[len(name)-1],
|
||||||
|
Color: label.Color,
|
||||||
|
ParentID: parentID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
conn.apiLabels[label.ID] = update
|
||||||
}, conn.apiLabelsLock)
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteMailbox deletes the label with the given ID.
|
// DeleteMailbox deletes the label with the given ID.
|
||||||
|
|||||||
Reference in New Issue
Block a user