github.com/pkg/sftp@v1.13.6/server_windows.go (about) 1 package sftp 2 3 import ( 4 "path" 5 "path/filepath" 6 ) 7 8 func (s *Server) toLocalPath(p string) string { 9 if s.workDir != "" && !path.IsAbs(p) { 10 p = path.Join(s.workDir, p) 11 } 12 13 lp := filepath.FromSlash(p) 14 15 if path.IsAbs(p) { 16 tmp := lp 17 for len(tmp) > 0 && tmp[0] == '\\' { 18 tmp = tmp[1:] 19 } 20 21 if filepath.IsAbs(tmp) { 22 // If the FromSlash without any starting slashes is absolute, 23 // then we have a filepath encoded with a prefix '/'. 24 // e.g. "/C:/Windows" to "C:\\Windows" 25 return tmp 26 } 27 28 tmp += "\\" 29 30 if filepath.IsAbs(tmp) { 31 // If the FromSlash without any starting slashes but with extra end slash is absolute, 32 // then we have a filepath encoded with a prefix '/' and a dropped '/' at the end. 33 // e.g. "/C:" to "C:\\" 34 return tmp 35 } 36 } 37 38 return lp 39 }