lib/model: Remove path from enc errors and report only once (#7610)
This commit is contained in:
+40
-3
@@ -15,6 +15,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -192,6 +193,8 @@ var (
|
|||||||
errEncryptionNotEncryptedRemote = errors.New("folder is configured to be encrypted but not announced thus")
|
errEncryptionNotEncryptedRemote = errors.New("folder is configured to be encrypted but not announced thus")
|
||||||
errEncryptionNotEncryptedUntrusted = errors.New("device is untrusted, but configured to receive not encrypted data")
|
errEncryptionNotEncryptedUntrusted = errors.New("device is untrusted, but configured to receive not encrypted data")
|
||||||
errEncryptionPassword = errors.New("different encryption passwords used")
|
errEncryptionPassword = errors.New("different encryption passwords used")
|
||||||
|
errEncryptionTokenRead = errors.New("failed to read encryption token")
|
||||||
|
errEncryptionTokenWrite = errors.New("failed to write encryption token")
|
||||||
errEncryptionNeedToken = errors.New("require password token for receive-encrypted token")
|
errEncryptionNeedToken = errors.New("require password token for receive-encrypted token")
|
||||||
errMissingRemoteInClusterConfig = errors.New("remote device missing in cluster config")
|
errMissingRemoteInClusterConfig = errors.New("remote device missing in cluster config")
|
||||||
errMissingLocalInClusterConfig = errors.New("local device missing in cluster config")
|
errMissingLocalInClusterConfig = errors.New("local device missing in cluster config")
|
||||||
@@ -1381,9 +1384,12 @@ func (m *model) ccHandleFolders(folders []protocol.Folder, deviceCfg config.Devi
|
|||||||
if sameError {
|
if sameError {
|
||||||
l.Debugln(msg)
|
l.Debugln(msg)
|
||||||
} else {
|
} else {
|
||||||
|
if rerr, ok := err.(*redactedError); ok {
|
||||||
|
err = rerr.redacted
|
||||||
|
}
|
||||||
|
m.evLogger.Log(events.Failure, err.Error())
|
||||||
l.Warnln(msg)
|
l.Warnln(msg)
|
||||||
}
|
}
|
||||||
m.evLogger.Log(events.Failure, err.Error())
|
|
||||||
return tempIndexFolders, paused, err
|
return tempIndexFolders, paused, err
|
||||||
}
|
}
|
||||||
if devErrs, ok := m.folderEncryptionFailures[folder.ID]; ok {
|
if devErrs, ok := m.folderEncryptionFailures[folder.ID]; ok {
|
||||||
@@ -1506,7 +1512,13 @@ func (m *model) ccCheckEncryption(fcfg config.FolderConfiguration, folderDevice
|
|||||||
var err error
|
var err error
|
||||||
token, err = readEncryptionToken(fcfg)
|
token, err = readEncryptionToken(fcfg)
|
||||||
if err != nil && !fs.IsNotExist(err) {
|
if err != nil && !fs.IsNotExist(err) {
|
||||||
return err
|
if rerr, ok := redactPathError(err); ok {
|
||||||
|
return rerr
|
||||||
|
}
|
||||||
|
return &redactedError{
|
||||||
|
error: err,
|
||||||
|
redacted: errEncryptionTokenRead,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
m.fmut.Lock()
|
m.fmut.Lock()
|
||||||
@@ -1514,7 +1526,14 @@ func (m *model) ccCheckEncryption(fcfg config.FolderConfiguration, folderDevice
|
|||||||
m.fmut.Unlock()
|
m.fmut.Unlock()
|
||||||
} else {
|
} else {
|
||||||
if err := writeEncryptionToken(ccToken, fcfg); err != nil {
|
if err := writeEncryptionToken(ccToken, fcfg); err != nil {
|
||||||
return err
|
if rerr, ok := redactPathError(err); ok {
|
||||||
|
return rerr
|
||||||
|
} else {
|
||||||
|
return &redactedError{
|
||||||
|
error: err,
|
||||||
|
redacted: errEncryptionTokenWrite,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m.fmut.Lock()
|
m.fmut.Lock()
|
||||||
m.folderEncryptionPasswordTokens[fcfg.ID] = ccToken
|
m.folderEncryptionPasswordTokens[fcfg.ID] = ccToken
|
||||||
@@ -3258,3 +3277,21 @@ type updatedPendingFolder struct {
|
|||||||
DeviceID protocol.DeviceID `json:"deviceID"`
|
DeviceID protocol.DeviceID `json:"deviceID"`
|
||||||
ReceiveEncrypted bool `json:"receiveEncrypted"`
|
ReceiveEncrypted bool `json:"receiveEncrypted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// redactPathError checks if the error is actually a os.PathError, and if yes
|
||||||
|
// returns a redactedError with the path removed.
|
||||||
|
func redactPathError(err error) (error, bool) {
|
||||||
|
perr, ok := err.(*os.PathError)
|
||||||
|
if !ok {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
return &redactedError{
|
||||||
|
error: err,
|
||||||
|
redacted: fmt.Errorf("%v: %w", perr.Op, perr.Err),
|
||||||
|
}, true
|
||||||
|
}
|
||||||
|
|
||||||
|
type redactedError struct {
|
||||||
|
error
|
||||||
|
redacted error
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user