Treat permission error as if file was deleted on windows
This commit is contained in:
parent
4b368d1590
commit
d9f4dcdb25
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/ActiveState/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