From 6aed3415c34c19e570e8677dbe2d602b4bae8ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Fri, 9 Feb 2024 10:58:20 +0100 Subject: [PATCH 1/3] Switch to csv format to avoid problems with spaces in dir or file names --- inotifywaitgo/command.go | 1 + inotifywaitgo/watcher.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/inotifywaitgo/command.go b/inotifywaitgo/command.go index 712272e..b25f149 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 { 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 } From 5350a5c8e9e1dfa7533b8150150838c34d304deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Fri, 9 Feb 2024 10:58:46 +0100 Subject: [PATCH 2/3] Fix cmdline when specifying multiple events --- inotifywaitgo/command.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inotifywaitgo/command.go b/inotifywaitgo/command.go index b25f149..6f62fee 100644 --- a/inotifywaitgo/command.go +++ b/inotifywaitgo/command.go @@ -28,19 +28,19 @@ 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 ") + baseCmd = append(baseCmd, EVENT_MAP[int(event)]) } } + baseCmd = append(baseCmd, s.Dir) + // remove spaces on all elements var outCmd []string for _, v := range baseCmd { From 08a5ed41830d063898a93c9886e6ed0b8d8c251a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Mon, 12 Feb 2024 08:22:56 +0100 Subject: [PATCH 3/3] Make the linter happy --- inotifywaitgo/command.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inotifywaitgo/command.go b/inotifywaitgo/command.go index 6f62fee..0729762 100644 --- a/inotifywaitgo/command.go +++ b/inotifywaitgo/command.go @@ -34,8 +34,7 @@ func GenerateBashCommands(s *Settings) ([]string, error) { if !Contains(VALID_EVENTS, int(event)) { return nil, errors.New(INVALID_EVENT) } - baseCmd = append(baseCmd, "-e ") - baseCmd = append(baseCmd, EVENT_MAP[int(event)]) + baseCmd = append(baseCmd, "-e ", EVENT_MAP[int(event)]) } }