refactor: use slices.Contains to simplify code (#10121)

There is a [new function](https://pkg.go.dev/slices@go1.21.0#Contains)
added in the go1.21 standard library, which can make the code more
concise and easy to read.
This commit is contained in:
pullmerge
2025-05-23 10:36:06 +00:00
committed by GitHub
parent 2532ac35cf
commit beda37f28b
3 changed files with 12 additions and 24 deletions
+4 -5
View File
@@ -21,6 +21,7 @@ import (
"path/filepath"
"reflect"
"runtime"
"slices"
"strings"
stdsync "sync"
"sync/atomic"
@@ -1804,11 +1805,9 @@ func (m *model) handleAutoAccepts(deviceID protocol.DeviceID, folder protocol.Fo
l.Infof("Failed to auto-accept folder %s from %s due to path conflict", folder.Description(), deviceID)
return config.FolderConfiguration{}, false
} else {
for _, device := range cfg.DeviceIDs() {
if device == deviceID {
// Already shared nothing todo.
return config.FolderConfiguration{}, false
}
if slices.Contains(cfg.DeviceIDs(), deviceID) {
// Already shared nothing todo.
return config.FolderConfiguration{}, false
}
if cfg.Type == config.FolderTypeReceiveEncrypted {
if len(ccDeviceInfos.remote.EncryptionPasswordToken) == 0 && len(ccDeviceInfos.local.EncryptionPasswordToken) == 0 {