diff --git a/inotifywaitgo/command.go b/inotifywaitgo/command.go index 712272e..0729762 100644 --- a/inotifywaitgo/command.go +++ b/inotifywaitgo/command.go @@ -17,6 +17,7 @@ func GenerateBashCommands(s *Settings) ([]string, error) { baseCmd := []string{ "inotifywait", + "-c", // switch to CSV output } if s.Options.Monitor { @@ -27,19 +28,18 @@ func GenerateBashCommands(s *Settings) ([]string, error) { baseCmd = append(baseCmd, "-r") } - baseCmd = append(baseCmd, s.Dir) - if len(s.Options.Events) > 0 { - baseCmd = append(baseCmd, "-e") for _, event := range s.Options.Events { // if event not in VALID_EVENTS if !Contains(VALID_EVENTS, int(event)) { return nil, errors.New(INVALID_EVENT) } - baseCmd = append(baseCmd, EVENT_MAP[int(event)]+" ") + baseCmd = append(baseCmd, "-e ", EVENT_MAP[int(event)]) } } + baseCmd = append(baseCmd, s.Dir) + // remove spaces on all elements var outCmd []string for _, v := range baseCmd { diff --git a/inotifywaitgo/watcher.go b/inotifywaitgo/watcher.go index d719128..b953744 100644 --- a/inotifywaitgo/watcher.go +++ b/inotifywaitgo/watcher.go @@ -2,6 +2,7 @@ package inotifywaitgo import ( "bufio" + "encoding/csv" "fmt" "log" "os" @@ -54,8 +55,11 @@ func WatchPath(s *Settings) { for scanner.Scan() { log.Println(scanner.Text()) line := scanner.Text() - parts := strings.Split(line, " ") - if len(parts) < 2 { + + r := csv.NewReader(strings.NewReader(line)) + + parts, err := r.Read() + if err != nil || len(parts) < 2 { s.ErrorChan <- fmt.Errorf(INVALID_OUTPUT) continue }