Skip to content

Commit

Permalink
Merge pull request #4 from aduffeck/main
Browse files Browse the repository at this point in the history
Fix handling names with spaces
  • Loading branch information
pablodz committed Feb 12, 2024
2 parents 81f73c4 + 08a5ed4 commit f54c624
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions inotifywaitgo/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func GenerateBashCommands(s *Settings) ([]string, error) {

baseCmd := []string{
"inotifywait",
"-c", // switch to CSV output
}

if s.Options.Monitor {
Expand All @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions inotifywaitgo/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package inotifywaitgo

import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit f54c624

Please sign in to comment.