Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling names with spaces #4

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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