syncthing/lib
Jakob Borg 3297624037
lib/ignore: Optimise ignoring directories for filesystem watcher (fixes #9339) (#9340)
This improves the ignore handling so that directories can be fully
ignored (skipped in the watcher) in more cases. Specifically, where the
previous rule was that any complex `!`-pattern would disable skipping
directories, the new rule is that only matches on patterns *after* such
a `!`-pattern disable skipping. That is, the following now does the
intuitive thing:

```
/foo
/bar
!whatever
*
```

- `/foo/**` and `/bar/**` are completely skipped, since there is no
chance anything underneath them could ever be not-ignored
- `!whatever` toggles the "can't skip directories any more" flag
- Anything that matches `*` can't skip directories, because it's
possible we can have `whatever` match something deeper.

To enable this, some refactoring was necessary:

- The "can skip dirs" flag is now a property of the match result, not of
the pattern set as a whole.
- That meant returning a boolean is not good enough, we need to actually
return the entire `Result` (or, like, two booleans but that seemed
uglier and more annoying to use)
- `ShouldIgnore(string) boolean` went away with
`Match(string).IsIgnored()` being the obvious replacement (API
simplification!)
- The watcher then needed to import the `ignore` package (for the
`Result` type), but `fs` imports the watcher and `ignore` imports `fs`.
That's a cycle, so I broke out `Result` into a package of its own so
that it can be safely imported everywhere in things like `type Matcher
interface { Match(string) result.Result }`. There's a fair amount of
stuttering in `result.Result` and maybe we should go with something like
`ignoreresult.R` or so, leaving this open for discussion.

Tests refactored to suit, I think this change is in fact quite well
covered by the existing ones...

Also some noise because a few of the changed files were quite old and
got the `gofumpt` treatment by my editor. Sorry not sorry.

---------

Co-authored-by: Simon Frei <freisim93@gmail.com>
2024-01-15 10:13:22 +00:00
..
api lib/api: Save session & CSRF tokens to database, add option to stay logged in (fixes #9151) (#9284) 2024-01-04 10:07:12 +00:00
assets lib/assets: MIME types, time formats (#8351) 2022-05-22 22:10:18 +02:00
beacon lib/beacon, lib/discover: Send IPv4 limited broadcast when address listing fails (fixes #1628) (#9087) 2023-09-12 14:28:17 +02:00
build lib/build: Allow semver build in version regex (fixes #9267) (#9316) 2024-01-02 20:43:22 +01:00
config Hide log out button when auth is not enabled (#9158) 2023-10-15 14:10:41 +02:00
connections lib/connections: Skip allocation in check for missing port (#9297) 2023-12-20 11:59:11 +01:00
db all: Remove lib/util package (#9049) 2023-08-21 19:44:33 +02:00
dialer lib: Removal global connection registry (#8254) 2022-04-09 16:04:56 +02:00
discover lib/beacon, lib/discover: Send IPv4 limited broadcast when address listing fails (fixes #1628) (#9087) 2023-09-12 14:28:17 +02:00
events all: Add Prometheus-style metrics to expose some internal performance counters (fixes #5175) (#9003) 2023-08-04 19:57:30 +02:00
fs lib/ignore: Optimise ignoring directories for filesystem watcher (fixes #9339) (#9340) 2024-01-15 10:13:22 +00:00
httpcache cmd/stupgrades: Cache should apply to HEAD as well as GET 2023-02-22 12:22:52 +01:00
ignore lib/ignore: Optimise ignoring directories for filesystem watcher (fixes #9339) (#9340) 2024-01-15 10:13:22 +00:00
locations lib/api: Save session & CSRF tokens to database, add option to stay logged in (fixes #9151) (#9284) 2024-01-04 10:07:12 +00:00
logger cmd/syncthing, lib/logger: Add date to default log format (fixes #8272) (#8273) 2022-04-15 07:46:14 +04:00
model lib/ignore: Refactor out result type (#9343) 2024-01-13 18:58:23 +01:00
nat lib/nat: Fix test build failure (ref #9010) 2023-12-11 10:13:14 +01:00
netutil all: Remove lib/util package (#9049) 2023-08-21 19:44:33 +02:00
osutil lib/osutil, lib/upnp: Check FlagRunning (fixes #8767) (#9047) 2023-08-21 14:49:28 +00:00
pmp lib/nat, lib/upnp: IPv6 UPnP support (#9010) 2023-12-11 07:36:18 +01:00
protocol gui: Keep short deviceID length consistent + xrefs (fixes #9313) (#9314) 2024-01-02 17:31:57 +01:00
rand all: Remove unused method receivers (#8462) 2022-07-28 17:32:45 +02:00
rc all: Remove unused method receivers (#8462) 2022-07-28 17:32:45 +02:00
relay cmd/strelaysrv: Add optional auth token (fixes #3987) (#8561) 2022-10-01 20:41:02 +01:00
scanner lib/ignore: Optimise ignoring directories for filesystem watcher (fixes #9339) (#9340) 2024-01-15 10:13:22 +00:00
semaphore all: Remove lib/util package (#9049) 2023-08-21 19:44:33 +02:00
sha256 all: Use crypt/rand through its buffered version, but not in benchmarks (#7420) 2021-03-02 19:17:20 +01:00
signature all: Use crypt/rand through its buffered version, but not in benchmarks (#7420) 2021-03-02 19:17:20 +01:00
sliceutil all: Support multiple device connections (fixes #141) (#8918) 2023-09-06 12:52:01 +02:00
stats all: Truncate some timestamps (fixes #7457) (#7459) 2021-03-12 10:35:10 +01:00
stringutil all: Remove lib/util package (#9049) 2023-08-21 19:44:33 +02:00
structutil all: Remove lib/util package (#9049) 2023-08-21 19:44:33 +02:00
stun all: Remove lib/util package (#9049) 2023-08-21 19:44:33 +02:00
svcutil all: Remove lib/util package (#9049) 2023-08-21 19:44:33 +02:00
sync lib/model: Use a single lock (phase two: cleanup) (#9276) 2023-12-11 22:06:45 +01:00
syncthing lib/api: Save session & CSRF tokens to database, add option to stay logged in (fixes #9151) (#9284) 2024-01-04 10:07:12 +00:00
testutil all: Remove lib/util package (#9049) 2023-08-21 19:44:33 +02:00
tlsutil lib/tlsutil: Use crypto.Signer interface (#8526) 2022-09-09 14:22:38 +02:00
upgrade lib/upgrade: Extract signing key to embedded file (fixes #9247) (#9296) 2023-12-18 19:47:57 +00:00
upnp lib/nat, lib/upnp: IPv6 UPnP support (#9010) 2023-12-11 07:36:18 +01:00
ur all: Remove lib/util package (#9049) 2023-08-21 19:44:33 +02:00
versioner lib/versioner: Expand tildes in version directory (fixes #9241) (#9327) 2024-01-12 10:46:18 +01:00
watchaggregator lib/config: Allow sub-second watcher delay (fixes #7859) (#7864) 2023-03-18 08:50:38 +01:00
weakhash all: Remove usage of deprecated io/ioutil (#7971) 2021-11-22 08:59:47 +01:00