summaryrefslogtreecommitdiff
path: root/fsnotify.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-06 17:51:41 -0600
committerJeff Carr <[email protected]>2024-01-06 17:51:41 -0600
commit1191d1548470a7ed1049f1d78de6f17b77e0d36d (patch)
treeb79d2773e77909b00b12c9250ea074a89df2b558 /fsnotify.go
parenta385734bc948b6cae6c5dd9a5fc48abaca4a040f (diff)
purge years of old test code
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'fsnotify.go')
-rw-r--r--fsnotify.go79
1 files changed, 0 insertions, 79 deletions
diff --git a/fsnotify.go b/fsnotify.go
deleted file mode 100644
index cf38b50..0000000
--- a/fsnotify.go
+++ /dev/null
@@ -1,79 +0,0 @@
-package main
-
-// Watches for changes to a directory. Works cross-platform
-
-import (
- "go.wit.com/log"
- "github.com/fsnotify/fsnotify"
-)
-
-// This would be a really dumb way to watch for new network interfaces
-// since it then watches a linux only directory /sys/class/net for changes
-
-func watchSysClassNet() {
- // Create new watcher.
- watcher, err := fsnotify.NewWatcher()
- if err != nil {
- log.Error(err, "watchSysClassNet() failed")
- return
- }
- defer watcher.Close()
-
- // Start listening for events.
- go func() {
- for {
- select {
- case event, ok := <-watcher.Events:
- if !ok {
- return
- }
- log.Println("event:", event)
- if event.Has(fsnotify.Write) {
- log.Println("modified file:", event.Name)
- }
- case err, ok := <-watcher.Errors:
- if !ok {
- return
- }
- log.Println("error:", err)
- }
- }
- }()
-
- // Add a path.
- err = watcher.Add("/tmp")
- if err != nil {
- log.Error(err, "watchSysClassNet() watcher.Add() failed")
- return
- }
-
- // Block main goroutine forever.
- <-make(chan struct{})
-}
-
-func fsnotifyNetworkInterfaceChanges() error {
- watcher, err := fsnotify.NewWatcher()
- if err != nil {
- return err
- }
- defer watcher.Close()
-
- // Watch for network interface changes
- err = watcher.Add("/sys/class/net")
- if err != nil {
- return err
- }
- for {
- select {
- case event := <-watcher.Events:
- log.Println("fsnotifyNetworkInterfaceChanges() event =", event)
- if event.Op&fsnotify.Create == fsnotify.Create {
- // Do something on network interface creation
- }
- case err := <-watcher.Errors:
- log.Println("fsnotifyNetworkInterfaceChanges() event err =", err)
- return err
- }
- }
-}
-