Skip to content

Conversation

rasa
Copy link
Member

@rasa rasa commented Apr 13, 2025

Fixes #10057: Support escaping in .stignore files on Windows
Fixes #7547: Ignore pattern with \[ and \] does not work

Purpose

Based on the discussion in
https://forum.syncthing.net/t/towards-syncthing-2-0/24072/35
this PR adds the ability for Windows users to use the pipe character (|) to escape the metacharacters *, ?, [, and { in .stignore files.

Additionally, this PR adds the ability for the user to set the escape character to backslash, or any character they want, by adding a line in the form:

#escape=X

(where X is any single rune), to the top of the .stginore file.

This would allow users to use the same .stignore files across platforms, by simply adding

#escape=\

to their files.

edit: Of course, when a Windows user does this, they will need replace any backslashes with forward slashes, so

\path\to\file-with-braces?1?.txt

would become:

#escape=\
/path/to/file-with-braces\[1\].txt

Testing

Tested on Ubuntu and Windows 11.

Documentation

I'll submit a PR to update the docs if this is accepted.

rasa added 3 commits April 13, 2025 12:52
Fixes syncthing#10057

Based on the discussion in
https://forum.syncthing.net/t/towards-syncthing-2-0/24072/35
This PR adds the ability for Windows users to use the pipe character (|) to
escape the metacharacters *, ?, [, and { in .stignore files.

Additionally, this PR adds the ability for the user to set the escape character
to backslash, or any character they want, by adding a line in the form:

 #escape=X

(where X is any single rune), to the top of the .stginore file.

This would allow users to use the same .stignore files across platforms, by
simply adding

 #escape=\

to their files.
@calmh calmh changed the title feat(ignore): Add .stignore escaping on Windows feat(ignore): add .stignore escaping on Windows Apr 23, 2025
rasa and others added 2 commits April 23, 2025 06:27
Co-authored-by: Jakob Borg <jakob@kastelo.net>
@calmh
Copy link
Member

calmh commented Apr 23, 2025

Do we also want to require having at most a single #escape line and having it before any ignore patterns in the file?

@rasa
Copy link
Member Author

rasa commented Apr 23, 2025

Do we also want to require having at most a single #escape line and having it before any ignore patterns in the file?

@calmh That seems entirely reasonable. I can't imagine a use case where they need to redefine it, or define it mid-file. I'll make it so.

@calmh
Copy link
Member

calmh commented Apr 24, 2025

Are there any considerations for includes? The setting is per file, right, with no infectiousness between files?

@rasa
Copy link
Member Author

rasa commented Apr 24, 2025

Are there any considerations for includes? The setting is per file, right, with no infectiousness between files?

@calmh Good question. Requiring the user to add it to each file is simpler, and won't surprise the user if they don't read the docs. But we could add a config option to change the default escape char for Windows users, if we want. Lemme know.

@calmh
Copy link
Member

calmh commented Apr 24, 2025

Let's not. I think it's better to account for ignore files being synced between different devices and make sure they're always interpreted the same based on just their content.

@rasa
Copy link
Member Author

rasa commented Apr 26, 2025

rasa added a commit to rasa/docs that referenced this pull request Apr 27, 2025
rasa added a commit to rasa/docs that referenced this pull request Apr 27, 2025
rasa added a commit to rasa/docs that referenced this pull request Apr 27, 2025
rasa added a commit to rasa/docs that referenced this pull request May 27, 2025
@calmh calmh force-pushed the v2 branch 2 times, most recently from 578cad6 to 43d33db Compare May 27, 2025 06:16
@github-actions github-actions bot added the enhancement New features or improvements of some kind, as opposed to a problem (bug) label May 30, 2025
@calmh calmh deleted the branch syncthing:v2 June 7, 2025 12:19
@calmh calmh closed this Jun 7, 2025
@rasa
Copy link
Member Author

rasa commented Jun 11, 2025

@calmh The errors in the logs were intermittent:

Attempting mirror: https://fs.liujiacai.net/zigbuilds
Mirror failed with error: Error: Unexpected HTTP response: 404

After merging main onto this branch, the latest run succeeded.

So please reconsider this PR, or let me know if there's anything I can do to improve it for reconsideration. Thanks.

@rasa
Copy link
Member Author

rasa commented Jun 29, 2025

@calmh This was closed without a comment. It was closed at the same time the v2 branch was deleted, so did it get closed automatically or accidentally?

@calmh
Copy link
Member

calmh commented Jun 29, 2025

Oh, accidentally. Repoint at main. That's what GitHub does when the target branch disappears, sorry.

@rasa
Copy link
Member Author

rasa commented Jun 29, 2025

@calmh No worries. The [Reopen and comment] button is grayed out for me. If you reopen, I will fix it. Or should I submit a new PR instead?

@calmh
Copy link
Member

calmh commented Jun 29, 2025

Same for me.

calmh pushed a commit to syncthing/docs that referenced this pull request Aug 7, 2025
Ref syncthing/syncthing#10058

---------

Co-authored-by: tomasz1986 <twilczynski@naver.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features or improvements of some kind, as opposed to a problem (bug)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants