fix(folder): apply default ignore settings for newly created folders (fixes #8816)#10112
fix(folder): apply default ignore settings for newly created folders (fixes #8816)#10112tejas-rkd wants to merge 1 commit intosyncthing:mainfrom
Conversation
|
I haven't tested the code, but could you confirm that this change doesn't reintroduce the bug from #7858? |
This is an interesting test case. Help me understand it.
So, I think we are good on this one? |
Yes, it does sound like there should be no problem with that 🙂. |
acolomb
left a comment
There was a problem hiding this comment.
Could you please explain in more detail what used to happen in the GUI with default ignore patterns configured? I thought it does already take care to load them as a template in the GUI. So how does that relate to the backend now adding the patterns as well?
Other than that, there's some style issues and code that could be simplified. Keeping the decision logic for "empty default ignores" in sync between GUI and backend would be important IMHO.
| if cfg.Type != config.FolderTypeReceiveEncrypted { | ||
| go func() { | ||
| ignores := m.cfg.DefaultIgnores() | ||
| // JS split() side effect. handling for empty ignore pattern. |
There was a problem hiding this comment.
This is the backend code in Go. Talking about JavaScript peculiarities here assumes that the GUI is the only consumer, while the backend's API should be agnostic.
The check itself could be moved to a helper method on the config.Ignores type, if we don't have it yet. That's cleaner than having the decision whether any ignores are set buried in this function.
So far it doesn't treat all-whitespace lines as being unset, right? Or am I misunderstanding the check for Lines[0] != ""?
| // a second step if the user indicates in the creation modal | ||
| // that they want to set ignores | ||
|
|
||
| // Reset _addIgnores to false by default for each new folder |
There was a problem hiding this comment.
This comment has no value, as it basically repeats what the code below says.
And please pay some attention to stray whitespace added by your editor.
| $scope.currentFolder._addIgnores = false; | ||
|
|
||
| if ($scope.config.defaults.ignores && $scope.config.defaults.ignores.lines) { | ||
| // split("\n") always returns a minimum 1-length array even for no patterns |
There was a problem hiding this comment.
While there might be a situation which requires this check, I think it should be rephrased / simplified. Nothing calls split() here, so the comment is confusing. If the intention is to detect an array of length 0, or with entries which are all falsy (empty strings), something like this would be more concise:
arr.length === 0 || arr.every(item => item === '');
Whatever check we end up with, you should put a comment hinting that the logic mirrors the decision in the backend.
Purpose
Fix inconsistent behavior where default ignore patterns weren't automatically applied when creating new folders. Previously, the "Add default ignore patterns" checkbox remained unchecked even when custom default ignores were configured, requiring users to manually enable this option for each new folder (fixes #8816).
Solution
addFolderInit()in the frontend to automatically check the "Add default ignore patterns" option when default patterns exist in the user's configurationnewFolder()function inmodel.goto ensure consistent application of default ignore patterns across all interfaces (GUI, CLI, and API)Testing