Hey @creature , sorry for the late response.
I actually gave up on the idea of parsing log files with scripts to determine this.
However, I did implement my own syncthing REST
API to fetch that information. It is appended at the bottom of this post. My approach is quite possibly dangerously idiotic since I am not familiar with syncthing’s codebase nor the Go language. It was an interesting excercise, and can definitely be improved. Maybe @calmh can take a quick look?
Nonetheless, it seems to be accurate (apparently there are ~35000 ignored files in one of my folders) and I will most certainly attempt to use it after I do some sanity checking (probably with a test case or something).
You use the API by issuing something like this:
curl -X GET -H "X-API-Key: <YOUR-API-KEY>" 'http://localhost:8384/rest/db/ignored?folder=<FOLDER-ID>'
The results (truncated file info) can be piped to jq or something, which is quite nice.
Cheers!
gui, model: add api for listing ignored files
From e4fb1eea15c67eaea416be4c4ea20578b21e5537 Mon Sep 17 00:00:00 2001
From: analogflow <analogflow@protonmail.com>
Date: Wed, 25 Apr 2018 00:05:37 +0200
Subject: [PATCH] gui, model: add api for listing ignored files
---
cmd/syncthing/gui.go | 11 +++++++++++
lib/model/model.go | 27 +++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go
index 29fc35b9..bec4e442 100644
--- a/cmd/syncthing/gui.go
+++ b/cmd/syncthing/gui.go
@@ -85,6 +85,7 @@ type modelIntf interface {
GlobalDirectoryTree(folder, prefix string, levels int, dirsonly bool) map[string]interface{}
Completion(device protocol.DeviceID, folder string) model.FolderCompletion
Override(folder string)
+ IgnoredFolderFiles(folder string) ([]db.FileInfoTruncated)
NeedFolderFiles(folder string, page, perpage int) ([]db.FileInfoTruncated, []db.FileInfoTruncated, []db.FileInfoTruncated)
RemoteNeedFolderFiles(device protocol.DeviceID, folder string, page, perpage int) ([]db.FileInfoTruncated, error)
NeedSize(folder string) db.Counts
@@ -259,6 +260,7 @@ func (s *apiService) Serve() {
getRestMux := http.NewServeMux()
getRestMux.HandleFunc("/rest/db/completion", s.getDBCompletion) // device folder
getRestMux.HandleFunc("/rest/db/file", s.getDBFile) // folder file
+ getRestMux.HandleFunc("/rest/db/ignored", s.getDBIgnored) // folder
getRestMux.HandleFunc("/rest/db/ignores", s.getDBIgnores) // folder
getRestMux.HandleFunc("/rest/db/need", s.getDBNeed) // folder [perpage] [page]
getRestMux.HandleFunc("/rest/db/remoteneed", s.getDBRemoteNeed) // device folder [perpage] [page]
@@ -760,6 +762,15 @@ func getPagingParams(qs url.Values) (int, int) {
return page, perpage
}
+func (s *apiService) getDBIgnored(w http.ResponseWriter, r *http.Request) {
+ qs := r.URL.Query()
+
+ folder := qs.Get("folder")
+ files := s.model.IgnoredFolderFiles(folder)
+
+ sendJSON(w, files)
+}
+
func (s *apiService) getDBNeed(w http.ResponseWriter, r *http.Request) {
qs := r.URL.Query()
diff --git a/lib/model/model.go b/lib/model/model.go
index c80149af..29486986 100644
--- a/lib/model/model.go
+++ b/lib/model/model.go
@@ -719,6 +719,33 @@ func (m *Model) NeedSize(folder string) db.Counts {
return result
}
+// IgnoredFolderFiles returns a list of currently ignored files
+func (m *Model) IgnoredFolderFiles(folder string) ([]db.FileInfoTruncated) {
+ m.fmut.RLock()
+ defer m.fmut.RUnlock()
+
+ ignores := m.folderIgnores[folder]
+ rf, ok := m.folderFiles[folder]
+ if !ok {
+ return nil
+ }
+
+ // files := make([]db.FileInfoTruncated, 0, maxBatchSizeFiles)
+ var files []db.FileInfoTruncated
+ rf.WithHaveTruncated(protocol.LocalDeviceID, func(fi db.FileIntf) bool {
+ f := fi.(db.FileInfoTruncated)
+ l.Debugf("%v IgnoredFolderFiles(%q): %v", m, folder, f)
+
+ if ignores.Match(f.Name).IsIgnored() {
+ files = append(files, f)
+ }
+
+ return true
+ })
+
+ return files
+}
+
// NeedFolderFiles returns paginated list of currently needed files in
// progress, queued, and to be queued on next puller iteration, as well as the
// total number of files currently needed.
--
2.17.0