Merge pull request #62 from florindragos/master

Treat permission error as if file was deleted on windows
This commit is contained in:
Nino Khodabandeh 2015-09-30 10:56:01 -07:00
commit 05d326f717
11 changed files with 23 additions and 53 deletions

View File

@ -1,17 +1,17 @@
FROM golang FROM golang
RUN mkdir -p $GOPATH/src/github.com/ActiveState/tail/ RUN mkdir -p $GOPATH/src/github.com/hpcloud/tail/
ADD . $GOPATH/src/github.com/ActiveState/tail/ ADD . $GOPATH/src/github.com/hpcloud/tail/
# expecting to fetch dependencies successfully. # 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. # 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 # expecting to install successfully
RUN go install -v github.com/ActiveState/tail RUN go install -v github.com/hpcloud/tail
RUN go install -v github.com/ActiveState/tail/cmd/gotail RUN go install -v github.com/hpcloud/tail/cmd/gotail
RUN $GOPATH/bin/gotail -h || true RUN $GOPATH/bin/gotail -h || true

View File

@ -8,4 +8,4 @@ fmt:
# Run the test in an isolated environment. # Run the test in an isolated environment.
fulltest: fulltest:
docker build -t activestate/tail . docker build -t hpcloud/tail .

View File

@ -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 # 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 ## Log rotation
@ -20,8 +20,8 @@ designed to work with log rotation tools.
## Installing ## Installing
go get github.com/ActiveState/tail/... go get github.com/hpcloud/tail/...
## Windows support ## 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.

View File

@ -5,7 +5,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/ActiveState/tail" "github.com/hpcloud/tail"
"os" "os"
) )

View File

@ -12,9 +12,9 @@ import (
"strings" "strings"
"time" "time"
"github.com/ActiveState/tail/ratelimiter" "github.com/hpcloud/tail/ratelimiter"
"github.com/ActiveState/tail/util" "github.com/hpcloud/tail/util"
"github.com/ActiveState/tail/watch" "github.com/hpcloud/tail/watch"
"gopkg.in/tomb.v1" "gopkg.in/tomb.v1"
) )

View File

@ -14,7 +14,7 @@ import (
"time" "time"
"./watch" "./watch"
"github.com/ActiveState/tail/ratelimiter" "github.com/hpcloud/tail/ratelimiter"
) )
func init() { func init() {

View File

@ -3,7 +3,7 @@
package tail package tail
import ( import (
"github.com/ActiveState/tail/winfile" "github.com/hpcloud/tail/winfile"
"os" "os"
) )

View File

@ -7,7 +7,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/ActiveState/tail/util" "github.com/hpcloud/tail/util"
"gopkg.in/fsnotify.v0" "gopkg.in/fsnotify.v0"
"gopkg.in/tomb.v1" "gopkg.in/tomb.v1"
) )

View File

@ -3,9 +3,10 @@
package watch package watch
import ( import (
"github.com/ActiveState/tail/util" "github.com/hpcloud/tail/util"
"gopkg.in/tomb.v1" "gopkg.in/tomb.v1"
"os" "os"
"runtime"
"time" "time"
) )
@ -51,8 +52,6 @@ func (fw *PollingFileWatcher) ChangeEvents(t *tomb.Tomb, origFi os.FileInfo) *Fi
go func() { go func() {
defer changes.Close() defer changes.Close()
var retry int = 0
prevSize := fw.Size prevSize := fw.Size
for { for {
select { select {
@ -64,16 +63,14 @@ func (fw *PollingFileWatcher) ChangeEvents(t *tomb.Tomb, origFi os.FileInfo) *Fi
time.Sleep(POLL_DURATION) time.Sleep(POLL_DURATION)
fi, err := os.Stat(fw.Filename) fi, err := os.Stat(fw.Filename)
if err != nil { 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). // File does not exist (has been deleted).
changes.NotifyDeleted() changes.NotifyDeleted()
return return
} }
if permissionErrorRetry(err, &retry) {
continue
}
// XXX: report this error back to the user // XXX: report this error back to the user
util.Fatal("Failed to stat file %v: %v", fw.Filename, err) util.Fatal("Failed to stat file %v: %v", fw.Filename, err)
} }

View File

@ -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
}

View File

@ -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
}