Skip to content

feat(ignore): add .stignore escaping on Windows - #10058

Closed
rasa wants to merge 9 commits into
syncthing:v2from
rasa:rs/feat-add-stignore-escaping
Closed

rasa wants to merge 9 commits into
syncthing:v2from
rasa:rs/feat-add-stignore-escaping

Conversation

@rasa

@rasa rasa commented Apr 13, 2025 •

Copy link
Copy Markdown
Member

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.
Comment thread lib/ignore/ignore.go Resolved
Comment thread lib/ignore/ignore.go Resolved
@calmh calmh changed the title feat(ignore): Add .stignore escaping on Windows feat(ignore): add .stignore escaping on Windows Apr 23, 2025
@calmh

calmh commented Apr 23, 2025

Copy link
Copy Markdown
Member

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

@rasa

rasa commented Apr 23, 2025

Copy link
Copy Markdown
Member Author

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

calmh commented Apr 24, 2025

Copy link
Copy Markdown
Member

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

@rasa

rasa commented Apr 24, 2025

Copy link
Copy Markdown
Member Author

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

calmh commented Apr 24, 2025

Copy link
Copy Markdown
Member

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

rasa commented Apr 26, 2025

Copy link
Copy Markdown
Member Author

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
Comment thread lib/ignore/ignore.go Resolved
Comment thread lib/ignore/ignore.go Resolved
Comment thread lib/ignore/ignore.go Resolved
Comment thread lib/ignore/ignore.go Resolved
Comment thread lib/ignore/ignore.go Resolved
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

rasa commented Jun 11, 2025

Copy link
Copy Markdown
Member Author

@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

rasa commented Jun 29, 2025

Copy link
Copy Markdown
Member Author

@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

calmh commented Jun 29, 2025 •

Copy link
Copy Markdown
Member

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

@rasa

rasa commented Jun 29, 2025 •

Copy link
Copy Markdown
Member Author

@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

calmh commented Jun 29, 2025

Copy link
Copy Markdown
Member

Same for me.

calmh pushed a commit to syncthing/docs that referenced this pull request Aug 7, 2025
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Jul 1, 2026
@syncthing syncthing locked and limited conversation to collaborators Jul 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New features or improvements of some kind, as opposed to a problem (bug) frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants