update change log, gofmt and remove debug prints
This commit is contained in:
parent
644891ebbc
commit
976fc15b81
|
@ -1,6 +1,8 @@
|
|||
# May, 2013
|
||||
|
||||
* Recognize deletions/renames when using polling file watcher (PR #1)
|
||||
* Detect file truncation
|
||||
* Fix potential race condition when reopening the file (issue 5)
|
||||
|
||||
# Feb, 2013
|
||||
|
||||
|
|
2
tail.go
2
tail.go
|
@ -186,7 +186,6 @@ func (tail *Tail) tailFileSync() {
|
|||
if !ok {
|
||||
changes = nil // XXX: how to kill changes' goroutine?
|
||||
|
||||
log.Println("Changes channel is closed.")
|
||||
// File got deleted/renamed/truncated.
|
||||
if tail.ReOpen {
|
||||
// TODO: no logging in a library?
|
||||
|
@ -208,7 +207,6 @@ func (tail *Tail) tailFileSync() {
|
|||
}
|
||||
}
|
||||
case <-tail.Dying():
|
||||
log.Println("Dying..")
|
||||
tail.close()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -138,7 +138,6 @@ func TestReOpenPolling(_t *testing.T) {
|
|||
_TestReOpen(_t, true)
|
||||
}
|
||||
|
||||
|
||||
func _TestReSeek(_t *testing.T, poll bool) {
|
||||
var name string
|
||||
if poll {
|
||||
|
@ -176,7 +175,7 @@ func _TestReSeek(_t *testing.T, poll bool) {
|
|||
<-time.After(100 * time.Millisecond)
|
||||
t.RemoveFile("test.txt")
|
||||
|
||||
println("Stopping...")
|
||||
println("Stopping (RESEEK)...")
|
||||
tail.Stop()
|
||||
}
|
||||
|
||||
|
@ -191,7 +190,6 @@ func TestReSeekPolling(_t *testing.T) {
|
|||
_TestReSeek(_t, true)
|
||||
}
|
||||
|
||||
|
||||
// Test library
|
||||
|
||||
type TailTest struct {
|
||||
|
|
13
watch.go
13
watch.go
|
@ -6,9 +6,8 @@ import (
|
|||
"github.com/howeyc/fsnotify"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
"sync"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FileWatcher monitors file-level events.
|
||||
|
@ -34,7 +33,6 @@ func NewInotifyFileWatcher(filename string) *InotifyFileWatcher {
|
|||
}
|
||||
|
||||
func (fw *InotifyFileWatcher) BlockUntilExists() error {
|
||||
fmt.Println("BUE(inotify): creating watcher")
|
||||
w, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -50,7 +48,6 @@ func (fw *InotifyFileWatcher) BlockUntilExists() error {
|
|||
}
|
||||
defer w.RemoveWatch(filepath.Dir(fw.Filename))
|
||||
|
||||
fmt.Println("BUE(inotify): does file exist now?")
|
||||
// Do a real check now as the file might have been created before
|
||||
// calling `WatchFlags` above.
|
||||
if _, err = os.Stat(fw.Filename); !os.IsNotExist(err) {
|
||||
|
@ -58,10 +55,8 @@ func (fw *InotifyFileWatcher) BlockUntilExists() error {
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("BUE(inotify): checking events (last: %v)\n", err)
|
||||
for {
|
||||
evt := <-w.Event
|
||||
fmt.Printf("BUE(inotify): got event: %v\n", evt)
|
||||
if evt.Name == fw.Filename {
|
||||
break
|
||||
}
|
||||
|
@ -93,7 +88,6 @@ func (fw *InotifyFileWatcher) ChangeEvents(fi os.FileInfo) chan bool {
|
|||
prevSize := fw.Size
|
||||
|
||||
evt := <-w.Event
|
||||
fmt.Printf("inotify change evt: %v\n", evt)
|
||||
switch {
|
||||
case evt.IsDelete():
|
||||
fallthrough
|
||||
|
@ -109,7 +103,6 @@ func (fw *InotifyFileWatcher) ChangeEvents(fi os.FileInfo) chan bool {
|
|||
}
|
||||
fw.Size = fi.Size()
|
||||
|
||||
fmt.Printf("WATCH(inotify): prevSize=%d; fs.Size=%d\n", prevSize, fw.Size)
|
||||
if prevSize > 0 && prevSize > fw.Size {
|
||||
return
|
||||
}
|
||||
|
@ -147,7 +140,6 @@ func (fw *PollingFileWatcher) BlockUntilExists() error {
|
|||
return err
|
||||
}
|
||||
time.Sleep(POLL_DURATION)
|
||||
println("blocking..")
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
@ -198,7 +190,6 @@ func (fw *PollingFileWatcher) ChangeEvents(origFi os.FileInfo) chan bool {
|
|||
|
||||
// Was the file truncated?
|
||||
fw.Size = fi.Size()
|
||||
fmt.Printf("WATCH(poll): prevSize=%d; fs.Size=%d\n", prevSize, fw.Size)
|
||||
if prevSize > 0 && prevSize > fw.Size {
|
||||
once.Do(stopAndClose)
|
||||
continue
|
||||
|
@ -212,8 +203,6 @@ func (fw *PollingFileWatcher) ChangeEvents(origFi os.FileInfo) chan bool {
|
|||
case ch <- true:
|
||||
default:
|
||||
}
|
||||
}else{
|
||||
fmt.Printf("polling; not modified: %v == %v\n", modTime, prevModTime)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue