Fix resolving chained symlinks with the WinFSP VFS#213
Fix resolving chained symlinks with the WinFSP VFS#213tomgr wants to merge 1 commit intobuildbarn:mainfrom
Conversation
|
c953f2d to
3bd8efc
Compare
|
Just converting to draft whilst I do a bit more testing. |
| // Parse the path to determine if it's absolute | ||
| w := relativePathChecker{} | ||
| if err := path.Resolve(path.LocalFormat.NewParser(string(target)), &w); err != nil { | ||
| return 0, err |
There was a problem hiding this comment.
If we change this:
if err := path.Resolve(path.LocalFormat.NewParser(string(target)), &w); err != nil {to:
targetParser := path.LocalFormat.NewParser(string(target))
if err := path.Resolve(targetParser, &w); err != nil {Then we can also the path library to do the sanitization:
cleanPathBuilder, scopeWalker := path.EmptyPath.Join(path.VoidScopeWalker)
if err := path.Resolve(targetParser, scopeWalker); err != nil {
return 0, err
}
cleanPath, err := cleanPathBuilder.GetWindowsString()
return 0, err
}I know it's more code, but at the same time it's a bit more future proof. At some point we may consider changing VirtualSymlink() and VirtualReadlink() to accept/return a path.Parser. That way the VFS API is completely oblivious of path separators. If/when that happens, this code will continue to work as expected.
There was a problem hiding this comment.
I've done this but it required some work on the path library to make it correctly handle more exotic windows paths: see buildbarn/bb-storage#329.
Once that's merged I'll update this PR with a reference to the appropriate commit.
3bd8efc to
077e871
Compare
2b574c1 to
93aca6b
Compare
a901b6a to
e67bcb4
Compare
ddc91b4 to
99fd38d
Compare
REv2 SymlinkNode targets use UNIX path separators `/`, and although Windows file paths should handle `/` or `\` equivalently, this is not the case when resolving symlink targets. In particular, symlink reparse buffers are documented as being pathnames, which means they must: 1) use the `\` separator; 2) if targetting a directory, it must not have a trailing `\` separator. We now normalise symlink targets on Windows when building the VFS entries to ensure they obey these rules.
99fd38d to
6be032c
Compare

It turns out that WinFSP's FspFileSystemFindReparsePoint only splits on backslashes when calculating reparse depth. Forward slashes in symlink targets (e.g. from VirtualSymlink) caused chained symlinks to fail. We now convert forward slashes to back slashes when returning the reparse point.