@@ -25,6 +25,7 @@ import (
25
25
"io/fs"
26
26
"os"
27
27
"path/filepath"
28
+ "runtime"
28
29
"strings"
29
30
"sync"
30
31
@@ -187,10 +188,24 @@ func MergeDir(dir string, conditions Conditions, opts *MergeDirOptions) ([]*File
187
188
if opts .AcceptFile == nil {
188
189
opts .AcceptFile = DefaultFileAcceptor
189
190
}
191
+ fmt .Printf ("BEFORE: dir=%q opts.FS=%#v\n " , dir , opts .FS )
190
192
if opts .FS == nil {
191
- opts .FS = os .DirFS (dir )
192
- dir = "."
193
+ // Go running on windows does not support os.DirFS properly
194
+ // See: https://github.com/golang/go/issues/44279
195
+ if runtime .GOOS == "windows" {
196
+ fmt .Println (" windows" )
197
+ opts .FS = & osFilesystem {}
198
+ } else {
199
+ fmt .Println (" other" )
200
+ opts .FS = os .DirFS (dir )
201
+ dir = "."
202
+ }
203
+ fmt .Printf ("MIDDLE1: dir=%q opts.FS=%#v\n " , dir , opts .FS )
204
+ }
205
+ if runtime .GOOS == "windows" {
206
+ dir = filepath .Join (filepath .VolumeName (dir ), dir )
193
207
}
208
+ fmt .Printf ("AFTER: dir=%q opts.FS=%#v\n " , dir , opts .FS )
194
209
195
210
sorted := & outFile {}
196
211
var setup sync.Once
@@ -278,6 +293,16 @@ func MergeDir(dir string, conditions Conditions, opts *MergeDirOptions) ([]*File
278
293
return convertToFiles (sorted , conditions )
279
294
}
280
295
296
+ // osFilesystem is an io/fs.FS which defers to the os package for opening files
297
+ // See: https://github.com/golang/go/issues/44279
298
+ type osFilesystem struct {}
299
+
300
+ func (* osFilesystem ) Open (name string ) (fs.File , error ) {
301
+ return os .Open (name )
302
+ }
303
+
304
+ var _ fs.FS = new (osFilesystem )
305
+
281
306
func walkDir (fsys fs.FS , dir string , discoveredPaths chan string ) error {
282
307
reader , ok := fsys .(fs.ReadDirFS )
283
308
if ! ok {
0 commit comments