Skip to content

Commit

Permalink
fix: defer to os.Open for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Mar 20, 2024
1 parent f5efa42 commit cb55bb5
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"io/fs"
"os"
"path/filepath"
"runtime"
"strings"
"sync"

Expand Down Expand Up @@ -188,8 +189,14 @@ func MergeDir(dir string, conditions Conditions, opts *MergeDirOptions) ([]*File
opts.AcceptFile = DefaultFileAcceptor
}
if opts.FS == nil {
opts.FS = os.DirFS(dir)
dir = "."
// Go running on windows does not support os.DirFS properly
// See: https://github.com/golang/go/issues/44279
if runtime.GOOS == "windows" {
opts.FS = &osFilesystem{}
} else {
opts.FS = os.DirFS(dir)
dir = "."
}
}

sorted := &outFile{}
Expand Down Expand Up @@ -278,6 +285,16 @@ func MergeDir(dir string, conditions Conditions, opts *MergeDirOptions) ([]*File
return convertToFiles(sorted, conditions)
}

// osFilesystem is an io/fs.FS which defers to the os package for opening files
// See: https://github.com/golang/go/issues/44279
type osFilesystem struct{}

func (*osFilesystem) Open(name string) (fs.File, error) {
return os.Open(name)
}

var _ fs.FS = new(osFilesystem)

func walkDir(fsys fs.FS, dir string, discoveredPaths chan string) error {
reader, ok := fsys.(fs.ReadDirFS)
if !ok {
Expand Down

0 comments on commit cb55bb5

Please sign in to comment.