added fsnotify example, to check bahavior on windows.
This commit is contained in:
		
							parent
							
								
									537579a567
								
							
						
					
					
						commit
						1ed49c638e
					
				
							
								
								
									
										58
									
								
								cmd/fsnotifytest/monitor.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								cmd/fsnotifytest/monitor.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,58 @@ | ||||
| package main | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 
 | ||||
| 	"github.com/fsnotify/fsnotify" | ||||
| ) | ||||
| 
 | ||||
| // create .hold
 | ||||
| //     CREATE + CHMOD
 | ||||
| // remove
 | ||||
| //     REMOVE
 | ||||
| // touch existing:
 | ||||
| //     CHMOD
 | ||||
| // echo > .hold
 | ||||
| //
 | ||||
| // file name:    ./.hold on linux
 | ||||
| 
 | ||||
| func main() { | ||||
| 	// Create a new watcher
 | ||||
| 	watcher, err := fsnotify.NewWatcher() | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
| 	defer watcher.Close() | ||||
| 
 | ||||
| 	// Start listening for events
 | ||||
| 	go func() { | ||||
| 		for { | ||||
| 			select { | ||||
| 			case event, ok := <-watcher.Events: | ||||
| 				if !ok { | ||||
| 					return | ||||
| 				} | ||||
| 				fmt.Printf("Event: %s File: %s\n", event.Op, event.Name) | ||||
| 
 | ||||
| 				if event.Op&fsnotify.Write == fsnotify.Write { | ||||
| 					fmt.Println("Modified file:", event.Name) | ||||
| 				} | ||||
| 			case err, ok := <-watcher.Errors: | ||||
| 				if !ok { | ||||
| 					return | ||||
| 				} | ||||
| 				fmt.Println("Error:", err) | ||||
| 			} | ||||
| 		} | ||||
| 	}() | ||||
| 
 | ||||
| 	// Add a directory to watch
 | ||||
| 	err = watcher.Add(".") | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
| 
 | ||||
| 	// Block main goroutine forever
 | ||||
| 	<-make(chan struct{}) | ||||
| } | ||||
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								go.mod
									
									
									
									
									
								
							| @ -5,6 +5,7 @@ go 1.21 | ||||
| require ( | ||||
| 	github.com/ActiveState/termtest/conpty v0.5.0 | ||||
| 	github.com/creack/pty v1.1.21 | ||||
| 	github.com/fsnotify/fsnotify v1.7.0 | ||||
| 	github.com/gliderlabs/ssh v0.3.7 | ||||
| 	github.com/gorilla/websocket v1.5.3 | ||||
| 	github.com/hashicorp/yamux v0.1.1 | ||||
|  | ||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
								
							| @ -9,6 +9,8 @@ github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr | ||||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= | ||||
| github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= | ||||
| github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE= | ||||
| github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8= | ||||
| github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= | ||||
|  | ||||
| @ -13,6 +13,15 @@ import ( | ||||
| 	_ "embed" | ||||
| ) | ||||
| 
 | ||||
| // TDDO fix concurrency
 | ||||
| // All methods put a message on a channel
 | ||||
| //
 | ||||
| // Using a channel of functions will work.
 | ||||
| // When default is used, channel will block always and thereby
 | ||||
| // effectively serializing everything.
 | ||||
| //
 | ||||
| // make(chan func())
 | ||||
| 
 | ||||
| // global configuration
 | ||||
| 
 | ||||
| type AgentState struct { | ||||
| @ -168,6 +177,7 @@ func (state *AgentState) expiryTime(filename string) time.Time { | ||||
| //  4. If the last user logs out, the aagent will exit immediately if no .hold file is
 | ||||
| //     present. Otherwise it will exit after the epxiry time. This allows users to
 | ||||
| //     reconnect later.
 | ||||
| 
 | ||||
| func check() { | ||||
| 	now := time.Now() | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user