Ignore updates for log file when watch is enabled (#2015)
* Ignore updates for log file when `watch` is enabled * Move check earlier * Ignore write event only * fix message
This commit is contained in:
1 parent
c3b184fc2e
commit
44e716d2f1
2 files changed
+16
-8
No files matched your search
@@ -298,6 +298,14 @@ func main() {
|
||||
gSocketProt = gDefaultSocketProt
|
||||
gSocketPath = gDefaultSocketPath
|
||||
|
||||
if gLogPath != "" {
|
||||
path, err := filepath.Abs(gLogPath)
|
||||
if err != nil {
|
||||
log.Fatalf("getting log path: %s", err)
|
||||
}
|
||||
gLogPath = path
|
||||
}
|
||||
|
||||
if *cpuprofile != "" {
|
||||
f, err := os.Create(*cpuprofile)
|
||||
if err != nil {
|
||||
@@ -319,14 +327,6 @@ func main() {
|
||||
log.Fatalf("remote command: %s", err)
|
||||
}
|
||||
case *serverMode:
|
||||
if gLogPath != "" && !filepath.IsAbs(gLogPath) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatalf("getting current directory: %s", err)
|
||||
} else {
|
||||
gLogPath = filepath.Join(wd, gLogPath)
|
||||
}
|
||||
}
|
||||
os.Chdir(gUser.HomeDir)
|
||||
serve()
|
||||
default:
|
||||
|
||||
@@ -96,6 +96,14 @@ func (watch *watch) loop() {
|
||||
}
|
||||
|
||||
if ev.Has(fsnotify.Write) || ev.Has(fsnotify.Chmod) {
|
||||
// skip write updates for the log file, otherwise it is possible
|
||||
// to have an infinite loop where writing to the log file causes
|
||||
// it to be reloaded, which in turn triggers more events that
|
||||
// are then logged
|
||||
if ev.Name == gLogPath && ev.Has(fsnotify.Write) {
|
||||
continue
|
||||
}
|
||||
|
||||
dir, file := filepath.Split(ev.Name)
|
||||
for _, path := range watch.getSameDirs(dir) {
|
||||
watch.addUpdate(filepath.Join(path, file))
|
||||
|
||||
Reference in new issue
Block a user