Skip to content

Commit 23ae4af

Browse files
committed
fix: defer to os.Open for windows
See: golang/go#44279
1 parent f5efa42 commit 23ae4af

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

merge.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"io/fs"
2626
"os"
2727
"path/filepath"
28+
"runtime"
2829
"strings"
2930
"sync"
3031

@@ -188,8 +189,15 @@ func MergeDir(dir string, conditions Conditions, opts *MergeDirOptions) ([]*File
188189
opts.AcceptFile = DefaultFileAcceptor
189190
}
190191
if opts.FS == nil {
191-
opts.FS = os.DirFS(dir)
192-
dir = "."
192+
// Go running on windows does not support os.DirFS properly
193+
// See: https://github.com/golang/go/issues/44279
194+
if runtime.GOOS == "windows" {
195+
opts.FS = &osFilesystem{}
196+
dir = filepath.Join(filepath.VolumeName(dir), dir)
197+
} else {
198+
opts.FS = os.DirFS(dir)
199+
dir = "."
200+
}
193201
}
194202

195203
sorted := &outFile{}
@@ -278,6 +286,16 @@ func MergeDir(dir string, conditions Conditions, opts *MergeDirOptions) ([]*File
278286
return convertToFiles(sorted, conditions)
279287
}
280288

289+
// osFilesystem is an io/fs.FS which defers to the os package for opening files
290+
// See: https://github.com/golang/go/issues/44279
291+
type osFilesystem struct{}
292+
293+
func (*osFilesystem) Open(name string) (fs.File, error) {
294+
return os.Open(name)
295+
}
296+
297+
var _ fs.FS = new(osFilesystem)
298+
281299
func walkDir(fsys fs.FS, dir string, discoveredPaths chan string) error {
282300
reader, ok := fsys.(fs.ReadDirFS)
283301
if !ok {

0 commit comments

Comments
 (0)