aboutsummaryrefslogtreecommitdiff
path: root/sftp/request_windows.go
blob: 1f6d3df170e8dabf329531338aa22672518e65e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package sftp

import (
	"path"
	"path/filepath"
	"syscall"
)

func fakeFileInfoSys() interface{} {
	return syscall.Win32FileAttributeData{}
}

func testOsSys(sys interface{}) error {
	return nil
}

func toLocalPath(p string) string {
	lp := filepath.FromSlash(p)

	if path.IsAbs(p) {
		tmp := lp
		for len(tmp) > 0 && tmp[0] == '\\' {
			tmp = tmp[1:]
		}

		if filepath.IsAbs(tmp) {
			// If the FromSlash without any starting slashes is absolute,
			// then we have a filepath encoded with a prefix '/'.
			// e.g. "/C:/Windows" to "C:\\Windows"
			return tmp
		}

		tmp += "\\"

		if filepath.IsAbs(tmp) {
			// If the FromSlash without any starting slashes but with extra end slash is absolute,
			// then we have a filepath encoded with a prefix '/' and a dropped '/' at the end.
			// e.g. "/C:" to "C:\\"
			return tmp
		}
	}

	return lp
}