File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
1212 "fmt"
1313 "os"
1414 "path/filepath"
15+ "reflect"
1516 "runtime"
1617 "sync"
1718 "syscall"
@@ -452,8 +453,16 @@ func (w *Watcher) readEvents() {
452453
453454 // Point "raw" to the event in the buffer
454455 raw := (* syscall .FileNotifyInformation )(unsafe .Pointer (& watch .buf [offset ]))
455- buf := (* [syscall .MAX_PATH ]uint16 )(unsafe .Pointer (& raw .FileName ))
456- name := syscall .UTF16ToString (buf [:raw .FileNameLength / 2 ])
456+ // TODO: Consider using unsafe.Slice that is available from go1.17
457+ // https://stackoverflow.com/questions/51187973/how-to-create-an-array-or-a-slice-from-an-array-unsafe-pointer-in-golang
458+ // instead of using a fixed syscall.MAX_PATH buf, we create a buf that is the size of the path name
459+ size := int (raw .FileNameLength / 2 )
460+ var buf []uint16
461+ sh := (* reflect .SliceHeader )(unsafe .Pointer (& buf ))
462+ sh .Data = uintptr (unsafe .Pointer (& raw .FileName ))
463+ sh .Len = size
464+ sh .Cap = size
465+ name := syscall .UTF16ToString (buf )
457466 fullname := filepath .Join (watch .path , name )
458467
459468 var mask uint64
You can’t perform that action at this time.
0 commit comments