Skip to content

Commit cb9f13f

Browse files
committed
cleaned up and added flag for container
1 parent 7358708 commit cb9f13f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

main.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"flag"
45
"fmt"
56
"os"
67
"os/exec"
@@ -12,8 +13,14 @@ import (
1213
)
1314

1415
var watcher *fsnotify.Watcher
16+
var container string
17+
18+
func init() {
19+
flag.StringVar(&container, "container", "radix-web-dev_container", "Name of the container instance that you wish to notify of filesystem changes")
20+
}
1521

1622
func main() {
23+
flag.Parse()
1724
watcher, _ = fsnotify.NewWatcher()
1825
defer watcher.Close()
1926

@@ -43,22 +50,21 @@ func notifyDocker(event fsnotify.Event) {
4350
if event.Op != fsnotify.Write {
4451
return
4552
}
53+
file := filepath.ToSlash(event.Name)
4654

47-
result, err := exec.Command("docker", "exec", "radix-web-dev_container", "stat", "-c", "%a", event.Name).Output()
48-
if strings.Contains(event.Name, ".git") {
49-
return
50-
}
55+
fmt.Println(fmt.Sprintf("%s: %s", event.Op, file))
56+
57+
result, err := exec.Command("docker", "exec", container, "stat", "-c", "%a", file).Output()
5158

5259
perms, err := strconv.Atoi(strings.TrimSuffix(string(result), "\n"))
5360
if err != nil {
5461
fmt.Println("Failed to convert permissions: ", err)
5562
return
5663
}
57-
_, err = exec.Command("docker", "exec", "radix-web-dev_container", "/bin/sh", "-c", fmt.Sprintf("chmod %d %s", perms, event.Name)).Output()
64+
_, err = exec.Command("docker", "exec", container, "/bin/sh", "-c", fmt.Sprintf("chmod %d %s", perms, file)).Output()
5865
if err != nil {
5966
fmt.Printf("Error notifying container about file change: %v", err)
6067
}
61-
fmt.Println(fmt.Sprintf("%s: %s", event.Op, event.Name))
6268
}
6369

6470
func watchDir(path string, fi os.FileInfo, err error) error {

0 commit comments

Comments
 (0)