gui: New rest endpoint to get errors when web UI is opened
Since #4340 pulls aren't happening every 10s anymore and may be delayed up to 1h. This means that no folder error event reaches the web UI for a long time, thus no failed items will show up for a long time. Now errors are populated when the web UI is opened. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4650 LGTM: AudriusButkevicius
This commit is contained in:
committed by
Audrius Butkevicius
parent
89a021609b
commit
fecb21cdb1
@@ -286,7 +286,7 @@ func (f *sendReceiveFolder) pull(prevIgnoreHash string) (curIgnoreHash string, s
|
||||
// we're not making it. Probably there are write
|
||||
// errors preventing us. Flag this with a warning and
|
||||
// wait a bit longer before retrying.
|
||||
if folderErrors := f.currentErrors(); len(folderErrors) > 0 {
|
||||
if folderErrors := f.PullErrors(); len(folderErrors) > 0 {
|
||||
events.Default.Log(events.FolderErrors, map[string]interface{}{
|
||||
"folder": f.folderID,
|
||||
"errors": folderErrors,
|
||||
@@ -1797,11 +1797,11 @@ func (f *sendReceiveFolder) clearErrors() {
|
||||
f.errorsMut.Unlock()
|
||||
}
|
||||
|
||||
func (f *sendReceiveFolder) currentErrors() []fileError {
|
||||
func (f *sendReceiveFolder) PullErrors() []FileError {
|
||||
f.errorsMut.Lock()
|
||||
errors := make([]fileError, 0, len(f.errors))
|
||||
errors := make([]FileError, 0, len(f.errors))
|
||||
for path, err := range f.errors {
|
||||
errors = append(errors, fileError{path, err})
|
||||
errors = append(errors, FileError{path, err})
|
||||
}
|
||||
sort.Sort(fileErrorList(errors))
|
||||
f.errorsMut.Unlock()
|
||||
@@ -1880,13 +1880,13 @@ func (f *sendReceiveFolder) deleteDir(dir string, ignores *ignore.Matcher, scanC
|
||||
return err
|
||||
}
|
||||
|
||||
// A []fileError is sent as part of an event and will be JSON serialized.
|
||||
type fileError struct {
|
||||
// A []FileError is sent as part of an event and will be JSON serialized.
|
||||
type FileError struct {
|
||||
Path string `json:"path"`
|
||||
Err string `json:"error"`
|
||||
}
|
||||
|
||||
type fileErrorList []fileError
|
||||
type fileErrorList []FileError
|
||||
|
||||
func (l fileErrorList) Len() int {
|
||||
return len(l)
|
||||
|
||||
Reference in New Issue
Block a user