server_plan9.go 459 B

123456789101112131415161718192021222324252627
  1. package sftp
  2. import (
  3. "path"
  4. "path/filepath"
  5. )
  6. func (s *Server) toLocalPath(p string) string {
  7. if s.workDir != "" && !path.IsAbs(p) {
  8. p = path.Join(s.workDir, p)
  9. }
  10. lp := filepath.FromSlash(p)
  11. if path.IsAbs(p) {
  12. tmp := lp[1:]
  13. if filepath.IsAbs(tmp) {
  14. // If the FromSlash without any starting slashes is absolute,
  15. // then we have a filepath encoded with a prefix '/'.
  16. // e.g. "/#s/boot" to "#s/boot"
  17. return tmp
  18. }
  19. }
  20. return lp
  21. }