@@ -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,39 @@ 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=%v opts.FS=%#v\n " , dir , opts .FS ) //nolint:forbidigo
192
+ // if runtime.GOOS == "windows" {
193
+ // // Go running on windows does not support os.DirFS properly
194
+ // // See: https://github.com/golang/go/issues/44279
195
+ // fmt.Println(" windows") //nolint:forbidigo
196
+ // opts.FS = &osFilesystem{}
197
+ // dir = filepath.Join(filepath.VolumeName(dir), dir)
198
+ // fmt.Printf("MIDDLE2: dir=%v opts.FS=%#v\n", dir, opts.FS) //nolint:forbidigo
199
+ // }
190
200
if opts .FS == nil {
201
+ fmt .Println (" other" ) //nolint:forbidigo
191
202
opts .FS = os .DirFS (dir )
192
203
dir = "."
204
+ fmt .Printf ("MIDDLE1: dir=%v opts.FS=%#v\n " , dir , opts .FS ) //nolint:forbidigo
205
+ } else {
206
+ var err error
207
+ fmt .Printf ("MIDDLE2A: dir=%v opts.FS=%#v\n " , dir , opts .FS ) //nolint:forbidigo
208
+ opts .FS , err = fs .Sub (opts .FS , dir )
209
+ if err != nil {
210
+ return nil , fmt .Errorf ("fs.Sub of %v and %v failed: %w" , opts .FS , dir , err )
211
+ }
212
+ if runtime .GOOS == "windows" {
213
+ dir = ""
214
+ } else {
215
+ dir = "."
216
+ }
217
+ fmt .Printf ("MIDDLE2B: dir=%v opts.FS=%#v\n " , dir , opts .FS ) //nolint:forbidigo
193
218
}
219
+ fmt .Printf ("AFTER: dir=%v opts.FS=%#v\n " , dir , opts .FS ) //nolint:forbidigo
220
+
221
+ // dir + sub: "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\TestMergeDir_SubFS959700692\\001\\a\\b\\c"
222
+ // BEFORE: dir="a\\b\\c" opts.FS="C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\TestMergeDir_SubFS959700692\\001"
223
+ // AFTER: dir="a\\b\\c" opts.FS="C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\TestMergeDir_SubFS959700692\\001"
194
224
195
225
sorted := & outFile {}
196
226
var setup sync.Once
@@ -278,7 +308,20 @@ func MergeDir(dir string, conditions Conditions, opts *MergeDirOptions) ([]*File
278
308
return convertToFiles (sorted , conditions )
279
309
}
280
310
311
+ // osFilesystem is an io/fs.FS which defers to the os package for opening files
312
+ // See: https://github.com/golang/go/issues/44279
313
+ type osFilesystem struct {}
314
+
315
+ func (* osFilesystem ) Open (name string ) (fs.File , error ) {
316
+ fmt .Printf ("osFilesystem.Open(%v)\n " , name ) //nolint:forbidigo
317
+ return os .Open (name )
318
+ }
319
+
320
+ var _ fs.FS = new (osFilesystem )
321
+
281
322
func walkDir (fsys fs.FS , dir string , discoveredPaths chan string ) error {
323
+ fmt .Printf ("walkDir: dir=%v fsys=%#v\n " , dir , fsys ) //nolint:forbidigo
324
+
282
325
reader , ok := fsys .(fs.ReadDirFS )
283
326
if ! ok {
284
327
return fmt .Errorf ("unexpected %T wanted fs.ReadDirFS" , fsys )
0 commit comments