Repository: syncthing/syncthing (language: go)

Issue:
Ignore patterns creating during folder addition are not loaded
### Include required information

Please be sure to include at least:

 - which version of Syncthing and what operating system you are using
   - 1.23.0
 - browser and version, if applicable
   - synctrazor/brave
 - what happened,
   - when accepting new folder share, after inserting Ignore Patterns the `.stignore` file is created automatically but in the GUI the Ignore Patterns show as empty, however, the file is not empty.  Syncthing is also not adhering to what is in `.stignore` and syncing all files.
 - what you expected to happen instead, and
   - Sync while respecting the Ignore Patterns in `.stignore`.  Maybe attempt to find the `#include` file first
 - any steps to reproduce the problem.
   - Yes, an example is below. Accept a new share from a remote pc.  Must use the `#include` function and make sure the `#include` file does not exist on host computer.
 - how to fix it
   - manually copy the `#include` file to the host computer and Syncthing will now load and use the Ignore Patterns. All `#include` files must exist

```
//global ignore file that contains unimportant extensions and files to ignore
#include .stignoresync

//exclude larger directories
bigfolder
biggerfolder
```



Discussion / hints:
What's supposed to happen when the ignore patterns have a bad #include is that the patterns fail to load and the folder is stopped. This does happen in the normal case, if it doesn't when accepting a share then that's the bug, but "partially" loading an .stignore while ignoring #includes is not a thing we do or should do...
Understandable, and good to know it should have stopped.

Currently, it did not stop.  I tried the same process on 2 different PCs and it kept syncing. It just thinks the ignore patterns are empty.


Yeah the `#include` stuff is a red herring, the real issue here is that adding ignore patters as described doesn't actually take effect on the folder. No idea why yet.
Came here to see if this was a known issue and report it if not. I've been trying out Syncthing with the hopes of moving over to it from Resilio. I have a workaround involving setting the pull order to "Smallest First", checking the box and adding my ignores, then doing "Pause All" followed by "Rescan All" once the #include files are synced. Maybe the ignores should be read and any #include files downloaded first? I'd figure this is possible since there are existing "Pull Order" options that must read the file data already.

Fix patch:
diff --git a/lib/ignore/ignore.go b/lib/ignore/ignore.go
index a26e73c7bf4..01960f3dd03 100644
--- a/lib/ignore/ignore.go
+++ b/lib/ignore/ignore.go
@@ -406,11 +406,19 @@ func loadParseIncludeFile(filesystem fs.Filesystem, file string, cd ChangeDetect
 	}
 
 	if cd.Seen(filesystem, file) {
-		return nil, parseError(fmt.Errorf("multiple include of ignore file %q", file))
+		return nil, errors.New("multiple include")
 	}
 
 	fd, info, err := loadIgnoreFile(filesystem, file)
 	if err != nil {
+		// isNotExist is considered "ok" in a sense of that a folder doesn't have to act
+		// upon it. This is because it is allowed for .stignore to not exist. However,
+		// included ignore files are not allowed to be missing and these errors should be
+		// acted upon on. So we don't perserve the error chain here and manually set an
+		// error instead, if the file is missing.
+		if fs.IsNotExist(err) {
+			err = errors.New("file not found")
+		}
 		return nil, err
 	}
 	defer fd.Close()


Test patch:
diff --git a/lib/ignore/ignore_test.go b/lib/ignore/ignore_test.go
index 231b926e93d..cf1b590a6e3 100644
--- a/lib/ignore/ignore_test.go
+++ b/lib/ignore/ignore_test.go
@@ -197,6 +197,11 @@ func TestBadPatterns(t *testing.T) {
 		if !IsParseError(err) {
 			t.Error("Should have been a parse error:", err)
 		}
+		if strings.HasPrefix(pat, "#include") {
+			if fs.IsNotExist(err) {
+				t.Error("Includes should not toss a regular isNotExist error")
+			}
+		}
 	}
 }