summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <git@mx.buetow.org>2020-12-27 16:31:03 +0000
committerPaul Buetow <git@mx.buetow.org>2020-12-27 16:31:03 +0000
commit94e37105c5a8c0ce22104add751e9938f239261e (patch)
tree410b98e4fa8cb722305c1feb6f8e286021805501
parenteca9c65b7c9e33cba8cc1ea5afe016bfc59f8918 (diff)
only try to read a file once in cat and grep mode but 10 times in tail mode
-rw-r--r--internal/server/handlers/readcommand.go20
-rw-r--r--internal/server/handlers/serverhandler.go4
-rw-r--r--internal/version/version.go2
3 files changed, 11 insertions, 15 deletions
diff --git a/internal/server/handlers/readcommand.go b/internal/server/handlers/readcommand.go
index 5b8ce3a..5bab26f 100644
--- a/internal/server/handlers/readcommand.go
+++ b/internal/server/handlers/readcommand.go
@@ -25,7 +25,7 @@ func newReadCommand(server *ServerHandler, mode omode.Mode) *readCommand {
}
}
-func (r *readCommand) Start(ctx context.Context, argc int, args []string) {
+func (r *readCommand) Start(ctx context.Context, argc int, args []string, retries int) {
re := regex.NewNoop()
if argc >= 4 {
@@ -40,21 +40,14 @@ func (r *readCommand) Start(ctx context.Context, argc int, args []string) {
r.server.sendServerWarnMessage(logger.Warn(r.server.user, commandParseWarning, args, argc))
return
}
- r.readGlob(ctx, args[1], re)
+ r.readGlob(ctx, args[1], re, retries)
}
-func (r *readCommand) readGlob(ctx context.Context, glob string, re regex.Regex) {
+func (r *readCommand) readGlob(ctx context.Context, glob string, re regex.Regex, retries int) {
retryInterval := time.Second * 5
glob = filepath.Clean(glob)
- maxRetries := 10
- for {
- maxRetries--
- if maxRetries < 0 {
- r.server.sendServerWarnMessage(logger.Warn(r.server.user, "Giving up to read file(s)"))
- return
- }
-
+ for retryCount := 0; retryCount < retries; retryCount++ {
paths, err := filepath.Glob(glob)
if err != nil {
logger.Warn(r.server.user, glob, err)
@@ -75,8 +68,11 @@ func (r *readCommand) readGlob(ctx context.Context, glob string, re regex.Regex)
}
r.readFiles(ctx, paths, glob, re, retryInterval)
- break
+ return
}
+
+ r.server.sendServerWarnMessage(logger.Warn(r.server.user, "Giving up to read file(s)"))
+ return
}
func (r *readCommand) readFiles(ctx context.Context, paths []string, glob string, re regex.Regex, retryInterval time.Duration) {
diff --git a/internal/server/handlers/serverhandler.go b/internal/server/handlers/serverhandler.go
index 681598c..185e7c2 100644
--- a/internal/server/handlers/serverhandler.go
+++ b/internal/server/handlers/serverhandler.go
@@ -258,7 +258,7 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int, args []
command := newReadCommand(h, omode.CatClient)
go func() {
h.incrementActiveReaders()
- command.Start(ctx, argc, args)
+ command.Start(ctx, argc, args, 1)
readerFinished()
commandFinished()
}()
@@ -267,7 +267,7 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int, args []
command := newReadCommand(h, omode.TailClient)
go func() {
h.incrementActiveReaders()
- command.Start(ctx, argc, args)
+ command.Start(ctx, argc, args, 10)
readerFinished()
commandFinished()
}()
diff --git a/internal/version/version.go b/internal/version/version.go
index 4fa9890..a64417f 100644
--- a/internal/version/version.go
+++ b/internal/version/version.go
@@ -13,7 +13,7 @@ const (
// Version of DTail.
Version string = "3.2.0"
// Additional information for DTail
- Additional string = "develop2"
+ Additional string = "develop-3"
// ProtocolCompat -ibility version.
ProtocolCompat string = "3"
)