Merge pull request #62 from florindragos/master
Treat permission error as if file was deleted on windows
This commit is contained in:
commit
05d326f717
12
Dockerfile
12
Dockerfile
|
@ -1,17 +1,17 @@
|
|||
FROM golang
|
||||
|
||||
RUN mkdir -p $GOPATH/src/github.com/ActiveState/tail/
|
||||
ADD . $GOPATH/src/github.com/ActiveState/tail/
|
||||
RUN mkdir -p $GOPATH/src/github.com/hpcloud/tail/
|
||||
ADD . $GOPATH/src/github.com/hpcloud/tail/
|
||||
|
||||
# expecting to fetch dependencies successfully.
|
||||
RUN go get -v github.com/ActiveState/tail
|
||||
RUN go get -v github.com/hpcloud/tail
|
||||
|
||||
# expecting to run the test successfully.
|
||||
RUN go test -v github.com/ActiveState/tail
|
||||
RUN go test -v github.com/hpcloud/tail
|
||||
|
||||
# expecting to install successfully
|
||||
RUN go install -v github.com/ActiveState/tail
|
||||
RUN go install -v github.com/ActiveState/tail/cmd/gotail
|
||||
RUN go install -v github.com/hpcloud/tail
|
||||
RUN go install -v github.com/hpcloud/tail/cmd/gotail
|
||||
|
||||
RUN $GOPATH/bin/gotail -h || true
|
||||
|
||||
|
|
2
Makefile
2
Makefile
|
@ -8,4 +8,4 @@ fmt:
|
|||
|
||||
# Run the test in an isolated environment.
|
||||
fulltest:
|
||||
docker build -t activestate/tail .
|
||||
docker build -t hpcloud/tail .
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[![Build Status](https://travis-ci.org/ActiveState/tail.svg)](https://travis-ci.org/ActiveState/tail)
|
||||
[![Build Status](https://travis-ci.org/hpcloud/tail.svg)](https://travis-ci.org/ActiveState/tail)
|
||||
|
||||
# Go package for tail-ing files
|
||||
|
||||
|
@ -11,7 +11,7 @@ for line := range t.Lines {
|
|||
}
|
||||
```
|
||||
|
||||
See [API documentation](http://godoc.org/github.com/ActiveState/tail).
|
||||
See [API documentation](http://godoc.org/github.com/hpcloud/tail).
|
||||
|
||||
## Log rotation
|
||||
|
||||
|
@ -20,8 +20,8 @@ designed to work with log rotation tools.
|
|||
|
||||
## Installing
|
||||
|
||||
go get github.com/ActiveState/tail/...
|
||||
go get github.com/hpcloud/tail/...
|
||||
|
||||
## Windows support
|
||||
|
||||
This package [needs assistance](https://github.com/ActiveState/tail/labels/Windows) for full Windows support.
|
||||
This package [needs assistance](https://github.com/hpcloud/tail/labels/Windows) for full Windows support.
|
||||
|
|
|
@ -5,7 +5,7 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/ActiveState/tail"
|
||||
"github.com/hpcloud/tail"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
|
6
tail.go
6
tail.go
|
@ -12,9 +12,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ActiveState/tail/ratelimiter"
|
||||
"github.com/ActiveState/tail/util"
|
||||
"github.com/ActiveState/tail/watch"
|
||||
"github.com/hpcloud/tail/ratelimiter"
|
||||
"github.com/hpcloud/tail/util"
|
||||
"github.com/hpcloud/tail/watch"
|
||||
"gopkg.in/tomb.v1"
|
||||
)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"time"
|
||||
|
||||
"./watch"
|
||||
"github.com/ActiveState/tail/ratelimiter"
|
||||
"github.com/hpcloud/tail/ratelimiter"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
package tail
|
||||
|
||||
import (
|
||||
"github.com/ActiveState/tail/winfile"
|
||||
"github.com/hpcloud/tail/winfile"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/ActiveState/tail/util"
|
||||
"github.com/hpcloud/tail/util"
|
||||
"gopkg.in/fsnotify.v0"
|
||||
"gopkg.in/tomb.v1"
|
||||
)
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
package watch
|
||||
|
||||
import (
|
||||
"github.com/ActiveState/tail/util"
|
||||
"github.com/hpcloud/tail/util"
|
||||
"gopkg.in/tomb.v1"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -51,8 +52,6 @@ func (fw *PollingFileWatcher) ChangeEvents(t *tomb.Tomb, origFi os.FileInfo) *Fi
|
|||
go func() {
|
||||
defer changes.Close()
|
||||
|
||||
var retry int = 0
|
||||
|
||||
prevSize := fw.Size
|
||||
for {
|
||||
select {
|
||||
|
@ -64,16 +63,14 @@ func (fw *PollingFileWatcher) ChangeEvents(t *tomb.Tomb, origFi os.FileInfo) *Fi
|
|||
time.Sleep(POLL_DURATION)
|
||||
fi, err := os.Stat(fw.Filename)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
// Windows cannot delete a file if a handle is still open (tail keeps one open)
|
||||
// so it gives access denied to anything trying to read it until all handles are released.
|
||||
if os.IsNotExist(err) || (runtime.GOOS == "windows" && os.IsPermission(err)) {
|
||||
// File does not exist (has been deleted).
|
||||
changes.NotifyDeleted()
|
||||
return
|
||||
}
|
||||
|
||||
if permissionErrorRetry(err, &retry) {
|
||||
continue
|
||||
}
|
||||
|
||||
// XXX: report this error back to the user
|
||||
util.Fatal("Failed to stat file %v: %v", fw.Filename, err)
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
// Copyright (c) 2013 ActiveState Software Inc. All rights reserved.
|
||||
// +build linux darwin freebsd
|
||||
|
||||
package watch
|
||||
|
||||
func permissionErrorRetry(err error, retry *int) bool {
|
||||
// No need for this on linux, don't retry
|
||||
return false
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
// +build windows
|
||||
|
||||
package watch
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
const permissionDeniedRetryCount int = 5
|
||||
|
||||
func permissionErrorRetry(err error, retry *int) bool {
|
||||
if os.IsPermission(err) && *retry < permissionDeniedRetryCount {
|
||||
// While pooling a file that does not exist yet, but will be created by another process we can get Permission Denied
|
||||
(*retry)++
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
Loading…
Reference in New Issue