sftp realpath: resolve symlinks

Fixes #890

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2022-07-17 16:02:45 +02:00
parent e0ce2e2e8a
commit 55b47cf741
14 changed files with 244 additions and 100 deletions

View File

@@ -308,9 +308,15 @@ func GetDirsForVirtualPath(virtualPath string) []string {
// CleanPath returns a clean POSIX (/) absolute path to work with
func CleanPath(p string) string {
return CleanPathWithBase("/", p)
}
// CleanPathWithBase returns a clean POSIX (/) absolute path to work with.
// The specified base will be used if the provided path is not absolute
func CleanPathWithBase(base, p string) string {
p = filepath.ToSlash(p)
if !path.IsAbs(p) {
p = "/" + p
p = path.Join(base, p)
}
return path.Clean(p)
}