Repository navigation
fix(gui): expand tildes for subdir check (fixes #9400) - #9788
Conversation
| // Tildes in both xdir and ydir are expanded for comparison | ||
| // so that e.g. xdir = "home/a/", ydir = "~/b" will return true. | ||
| function isSubDir(xdir, ydir) { | ||
| xdir = xdir.replace("~", scope.system.tilde); |
There was a problem hiding this comment.
I don't think we want /home/foo/my~dir/ to get expanded though, so this should probably be limited to replacing tilde followed by slash (and maybe backslash) at the beginning of the string?
There was a problem hiding this comment.
You're right. I adapted the replace call. Thank you for the fast review btw! :)
Signed-off-by: tobifroe <[email protected]>
| var tildeExpansionRegex = new RegExp("^~\/"); | ||
| xdir = xdir.replace(tildeExpansionRegex, `${scope.system.tilde}/`); | ||
| ydir = ydir.replace(tildeExpansionRegex, `${scope.system.tilde}/`); |
There was a problem hiding this comment.
I think you want to use scope.system.pathSeparator instead of a hardcoded slash. And perhaps, since we split on that on the line below, perhaps then just check if the first component is ~?
There was a problem hiding this comment.
I replaced the hardcoded slash with scope.system.pathSeperator. I do think we need to check for ~/ at the beginning of the string since we wouldn't want to expand ~my-dir/foo, right?
There was a problem hiding this comment.
Not asking for any change, just trying to clarify if it's of any interest to you:
How I understand @calmh's suggestion that still works, but no regex required: After splitting, you check that xdirArr[0] === "~" and then replace that. For ~my-dir/foo the array will be [~my-dir, foo], so no match/replace. The small downside: You need to split the expanded tilde again. The upside: No regex or handling of separator types needed, you just get the same behaviour as splitting (rightly or wrongly, but if it's wrong fixing both tilde and splitting consistently would be nice).
|
Note that on Windows, both The same incorrect check happens in |
|
The backslash is not special on other OSes, so would it make more sense to check for ( |
|
@acolomb Shouldn't we check for |
|
Sorry, that was a typo of mine. Of course I meant: On Windows, the browser's debug console tells me that the latter is |
|
Thank you for clarifying @acolomb, changed the regex to reflect that. |
imsodin
left a comment
There was a problem hiding this comment.
Approved, the below is just a meta-comment on reviewing.
by @acolomb:
Note that on Windows, both
\and/are considered as path separators. We should treat both~/and~\as referring to the home directory.
This is a case of requiring a PR to do more than what it's main intent is. I believe we should generally not do that, resp. at most suggest that as an optional extension of the main intent. Sometimes it might not be clear if the proposal is integral to the change at hand or not - one possible litmus test is to ask yourself if the change is a net improval without it already (obviously neither final nor complete criteria). Feature creep can introduce all kinds of issues (delaying PRs, introducing unexpected side effects). Don't get me wrong, it's great if we find additional, concrete improvements during a PR, I just would like to see those more treated as optional suggestions than integral parts of the review.
|
@calmh Policybot is listing a missing contributor approval. I noticed that before on PRs you approved. I don't see a way to "kick it" to make it re-evaluate the situation (some CI solution at work is very prone to missing hooks, that's why "kick it" is an ingrained action for me :) ) - do you know of one? Or any known issues/ideas/... for dealing with/troubleshooting this? |
|
@imsodin It's silliness... your review is disqualified since you've pushed a commit and become a contributor. Merge commits shouldn't count towards that though, I'll see if I can fix what the problem is. |
@imsodin Thanks for the heads up, will try to keep it in mind next time. However, to defend the circumstances here, I was reacting to a previous review comment which suggested using the |
|
@acolomb Fair point. I also came to this PR a lot later - with hindsight it's very easy to to find things to (potentially) improve (if it even applies here). |
* upstream/main: chore: update policy to allow approvals by contributors (syncthing#9818) fix(gui): expand tildes for subdir check (fixes syncthing#9400) (syncthing#9788)
Purpose
This closes #9400 by always expanding tildes when parent/subdir checks are done.
Testing
I tested this by creating folders with paths to parent or subdirectories of the default folder that include a tilde in their path as shown in the attached screenshots.
With this change, overlap will be detected regardless of wether or not tildes are used in other folder paths.
Screenshots
Default Folder:


Newly created folder (parent directory in this case)