@@ -18,7 +18,11 @@ func (s *Server) toLocalPath(p string) string {
18
18
19
19
lp := filepath .FromSlash (p )
20
20
21
- if path .IsAbs (p ) {
21
+ if path .IsAbs (p ) { // starts with '/'
22
+ if len (p ) == 1 {
23
+ return `\\.\` // for openfile
24
+ }
25
+
22
26
tmp := lp
23
27
for len (tmp ) > 0 && tmp [0 ] == '\\' {
24
28
tmp = tmp [1 :]
@@ -39,6 +43,11 @@ func (s *Server) toLocalPath(p string) string {
39
43
// e.g. "/C:" to "C:\\"
40
44
return tmp
41
45
}
46
+
47
+ if s .winRoot {
48
+ // Make it so that "/Windows" is not found, and "/c:/Windows" has to be used
49
+ return `\\.\` + tmp
50
+ }
42
51
}
43
52
44
53
return lp
@@ -93,19 +102,17 @@ func newWinRoot() (*winRoot, error) {
93
102
94
103
func (f * winRoot ) Readdir (n int ) ([]os.FileInfo , error ) {
95
104
drives := f .drives
96
- if n > 0 {
97
- if len (drives ) > n {
98
- drives = drives [:n ]
99
- }
100
- f .drives = f .drives [len (drives ):]
101
- if len (drives ) == 0 {
102
- return nil , io .EOF
103
- }
105
+ if n > 0 && len (drives ) > n {
106
+ drives = drives [:n ]
107
+ }
108
+ f .drives = f .drives [len (drives ):]
109
+ if len (drives ) == 0 {
110
+ return nil , io .EOF
104
111
}
105
112
106
113
var infos []os.FileInfo
107
114
for _ , drive := range drives {
108
- fi , err := os .Stat (drive )
115
+ fi , err := os .Stat (drive + `\` )
109
116
if err != nil {
110
117
return nil , err
111
118
}
@@ -120,8 +127,8 @@ func (f *winRoot) Readdir(n int) ([]os.FileInfo, error) {
120
127
return infos , nil
121
128
}
122
129
123
- func openfile (path string , flag int , mode fs.FileMode ) (file , error ) {
124
- if path == "/" {
130
+ func ( s * Server ) openfile (path string , flag int , mode fs.FileMode ) (file , error ) {
131
+ if path == `\\.\` && s . winRoot {
125
132
return newWinRoot ()
126
133
}
127
134
return os .OpenFile (path , flag , mode )
0 commit comments