Skip to content

lib/fs: Don't add path separators at path ends (ref #5144) - #5146

Merged
calmh merged 1 commit into
syncthing:masterfrom
imsodin:rootedWindows
Aug 28, 2018
Merged

calmh merged 1 commit into
syncthing:masterfrom
imsodin:rootedWindows

Conversation

@imsodin

@imsodin imsodin commented Aug 26, 2018

Copy link
Copy Markdown
Member

Purpose

By @calmh in #5144

We take great care to make sure a folder root doesn't end in slash on Windows...

Right. But then we do the "rooted". This (new) fs test should pass, imho:

func TestWindowsFolderRoot(t *testing.T) {
	fs := BasicFilesystem{root: `c:\test`}
	rooted, err := fs.rooted(".")
	if err != nil {
		t.Fatal(err)
	}
	if rooted != `c:\test` {
		t.Error("Incorrect root:", rooted)
	}
}

But it does not:

basicfs_windows_test.go:101: Incorrect root: c:\test\

So we undo the efforts of our root normalization stuff from earlier...

This treats the case specially when the path given to rooted is equivalent to . (folder root), in that it just returns BasicFilesystem.root without modifying it, thus leaving the precautions taken in newBasicFilesystem untouched.

Testing

Needed to adjust and add some test cases to TestRooted and added the test proposed by Jakob above.

@calmh

calmh commented Aug 26, 2018

Copy link
Copy Markdown
Member

I don't think that's the right precaution. I think the right one is "paths on windows should never end in slash" and if we do that in rooted() we might not need to also do it in the fs constructor...

@imsodin

imsodin commented Aug 26, 2018

Copy link
Copy Markdown
Member Author

@calmh Then I think we need to talk about all the path separator precautions in place, and which is really the desired behaviour. From the current implementation:

  1. On Windows drive letters as folder root get a trailing path set: C: -> C:\
  2. On Windows folder roots do not have a trailing path sep.
  3. On all other platforms roots must have a trailing path sep (to penetrate symlinks).
  4. Rooted paths other than . never have a trailing path sep.
  5. . when rooted gets a trailing path sep.

Now apparently the no trailing path separator on windows ever seems to be a valid concern. I do not see what's the reason for 3. - how do trailing path separators help penetrate symlinks? And why would that even be desired? Generally the "canonical" form of paths is Go is without a trailing path separator (which is also pretty usual in other places as far as I know).

So unless there is a good reason for 3, I'd say we just go with no trailing path separator in the resulting paths (steps in between might still require it due to HasPrefix checks, but that need not influence the final result)

@calmh

calmh commented Aug 26, 2018 via email

Copy link
Copy Markdown
Member

@calmh

calmh commented Aug 26, 2018

Copy link
Copy Markdown
Member

[Step 5/5] open C:\BuildAgent\temp\buildTmp\go-build518408782\b001\exe\a.out.exe: Operation did not complete successfully because the file contains a virus or potentially unwanted software.

😞

@calmh

calmh commented Aug 26, 2018 •

Copy link
Copy Markdown
Member

I had a frank discussion with Windows Defender and I think we managed to agree that the build agent artifacts are not to be considered threats henceforth. (Please don't abuse this trust :D)

This LGTM - or rather, it looks like we're removing some safety checks, but the tests that verify them still pass so I'm OK with that. I think my new temporary test should just be folded into the list of paths that we already check in the other test you tweaked, last among the "windows special items" that already checked we handled the c:\ root correctly.

But that's a nit. 👍 from me

@imsodin imsodin changed the title lib/fs: Don't append path sep to root in rooted (ref #5144) lib/fs: Don't add path separators at path ends (ref #5144) Aug 26, 2018
@imsodin

imsodin commented Aug 26, 2018

Copy link
Copy Markdown
Member Author

@calmh

Thanks for taking care of that devil (well generally taking care of that wind... stuff :) ).

The removed safety checks were redundant since the introduction of Canonicalize.

I addressed the nit and rebased, as the original commits and commit messages aren't relevant anymore.

@calmh
calmh merged commit c62ce00 into syncthing:master Aug 28, 2018
@imsodin
imsodin deleted the rootedWindows branch August 28, 2018 06:29
calmh added a commit to calmh/syncthing that referenced this pull request Sep 2, 2018
* release:
  lib/model: Fixes on receive-only test setup and pulling (syncthing#5136)
  lib/fs: Don't add path separators at end of path (fixes syncthing#5144) (syncthing#5146)
  lib/fs: Evaluate root when watching not on fs creation (fixes syncthing#5043) (syncthing#5105)
@calmh calmh added this to the v0.14.51 milestone Sep 2, 2018
@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 Aug 28, 2019
@syncthing syncthing locked and limited conversation to collaborators Aug 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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