Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(folder): apply default ignore settings for newly created folders (fixes #8816)#10112

Open
tejas-rkd wants to merge 1 commit intosyncthing:mainfrom
tejas-rkd:fix-8816
Open

fix(folder): apply default ignore settings for newly created folders (fixes #8816)#10112
tejas-rkd wants to merge 1 commit intosyncthing:mainfrom
tejas-rkd:fix-8816

Conversation

@tejas-rkd
Copy link

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

  • Modified addFolderInit() in the frontend to automatically check the "Add default ignore patterns" option when default patterns exist in the user's configuration
  • Updated the newFolder() function in model.go to ensure consistent application of default ignore patterns across all interfaces (GUI, CLI, and API)
  • Logic now properly evaluates whether default ignore patterns are present before setting the option

Testing

  1. Verified that when default ignore patterns are configured, the checkbox is automatically selected when creating new folders
  2. Confirmed that with empty default ignore patterns, the checkbox remains unchecked by default
  3. Validated that editing existing folders' ignore patterns remains unaffected
  4. Tested folder creation via CLI with default patterns configured and verified .stignore files are properly created with the expected rules
  5. Confirmed CLI folder creation with no default patterns results in no additional files being created

@tomasz1986
Copy link
Member

I haven't tested the code, but could you confirm that this change doesn't reintroduce the bug from #7858?

@tejas-rkd
Copy link
Author

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.
Based on my comprehension, I tested following:

  1. Add Default Ignore patterns in Advance
  2. Create folder using path /, check to add ignore pattern.
  3. Folder gets created with Stopped status and in detailed view, no ignore patterns are seen.
  4. Create another folder using valid path
  5. Folder gets created with Unshared status and in detailed view, ignore patterns are added.

So, I think we are good on this one?

@tejas-rkd tejas-rkd marked this pull request as ready for review May 19, 2025 12:12
@tomasz1986
Copy link
Member

So, I think we are good on this one?

Yes, it does sound like there should be no problem with that 🙂.

Copy link
Member

@acolomb acolomb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions bot added the bug A problem with current functionality, as opposed to missing functionality (enhancement) label May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug A problem with current functionality, as opposed to missing functionality (enhancement)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'Advanced Configuration > Default Ignore Patterns' doesn't have any effect

3 participants