small adjustment
This commit is contained in:
parent
df63fe10d7
commit
95827a2efe
@ -9,6 +9,7 @@ import (
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
@ -47,7 +48,7 @@ func main() {
|
||||
go createEmptyAndDelete(ctx, sm, time.Second+(time.Millisecond*600), dir2Watch)
|
||||
|
||||
done := make(chan os.Signal, 1)
|
||||
signal.Notify(done, os.Interrupt)
|
||||
signal.Notify(done, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
fmt.Println("watching the directory, press ctrl-c to stop...")
|
||||
<-done
|
||||
@ -159,15 +160,17 @@ func createEmptyAndDelete(ctx context.Context, sm *sync.Map, initialWait time.Du
|
||||
switch next {
|
||||
case createFile:
|
||||
nextFileName = filepath.Join(dir, nextFileName)
|
||||
log.Printf("creating file: %s\n", nextFileName)
|
||||
if f, err = os.OpenFile(nextFileName, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0666); err != nil {
|
||||
log.Printf("Error creating file %s: %+v", nextFileName, err)
|
||||
log.Printf("Error creating file %s: %+v\n", nextFileName, err)
|
||||
return
|
||||
}
|
||||
_ = f.Close()
|
||||
next = deleteFile
|
||||
case deleteFile:
|
||||
log.Printf("deleting file: %s\n", nextFileName)
|
||||
if err = os.Remove(nextFileName); err != nil {
|
||||
log.Printf("Error deleting file %s: %+v", nextFileName, err)
|
||||
log.Printf("Error deleting file %s: %+v\n", nextFileName, err)
|
||||
return
|
||||
}
|
||||
next = createFile
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user