From 966df032a61067d83f06445bca5771624130365a Mon Sep 17 00:00:00 2001 From: Seednode Date: Sat, 18 Feb 2023 14:08:11 -0600 Subject: [PATCH] Added retry to new file selection, with 10s timeout --- cmd/files.go | 16 +++++----------- cmd/version.go | 2 +- cmd/web.go | 20 ++++++++++++++++---- stats.file | Bin 1648 -> 0 bytes 4 files changed, 22 insertions(+), 16 deletions(-) delete mode 100644 stats.file diff --git a/cmd/files.go b/cmd/files.go index 86262f9..26675e0 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -517,39 +517,33 @@ func prepareDirectory(directory []string) []string { last = cleanFilename(last) if first == last { - return append([]string{}, directory[0]) + return []string{directory[0]} } else { return directory } } func prepareDirectories(files *Files, sort string) []string { - i, l := 0, 0 - - files.mutex.RLock() + directories := []string{} keys := make([]string, len(files.list)) + i := 0 for k := range files.list { keys[i] = k i++ - l += len(files.list[k]) } - directories := make([]string, l) - if sort == "asc" || sort == "desc" { for i := 0; i < len(keys); i++ { - copy(directories, prepareDirectory(files.list[keys[i]])) + directories = append(directories, prepareDirectory(files.list[keys[i]])...) } } else { for i := 0; i < len(keys); i++ { - copy(directories, files.list[keys[i]]) + directories = append(directories, files.list[keys[i]]...) } } - files.mutex.RUnlock() - return directories } diff --git a/cmd/version.go b/cmd/version.go index e21f671..0536d0b 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.38.1" +var Version = "0.38.2" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index fcf1088..d003691 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -35,9 +35,10 @@ var ( ) const ( - LogDate string = `2006-01-02T15:04:05.000-07:00` - Prefix string = `/src` - RedirectStatusCode int = http.StatusSeeOther + LogDate string = `2006-01-02T15:04:05.000-07:00` + Prefix string = `/src` + RedirectStatusCode int = http.StatusSeeOther + Timeout time.Duration = 10 * time.Second ) type Regexes struct { @@ -682,7 +683,18 @@ func serveHtmlHandler(paths []string, Regexes *Regexes, index *Index) http.Handl } } - if filePath == "" { + loop: + for timeout := time.After(Timeout); ; { + select { + case <-timeout: + break loop + default: + } + + if filePath != "" { + break loop + } + filePath, err = newFile(paths, filters, sortOrder, Regexes, index) switch { case err != nil && err == ErrNoImagesFound: diff --git a/stats.file b/stats.file deleted file mode 100644 index 232038bde6b13153ba9844bdf4323d07ef5fc386..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1648 zcmV-$29NnDwJ-f-luH#e0E$2;3_DPbQXn%kGo#7O%*>1_#3vx_0I|{@B6mH=B!T71 z8ntb#GO#$Y<7KDx)BoxJwCRRHU}so~?8=NS$<_eC0G|LN7_CYWQZi+LP67ng4&2i%1~8BO_xeFN21I|MWm8CD$|Ngqz$Hm zfeIm^HX0QXjZ{@;hN@736tE2!362tu)8S$k%o#y|F$xhE0>`mn7R(6&;yU0s53^`! zX`~Vf5lEtp0LCahTn8M-VnicttV%)z3S$!-t^$tZjJQ}eGZIJu=7hM|%piSGFz3U? zEKLcO5r8=zE@o8{M8PPSv*BWu6cIu7L1o%V44Q_@OpS)oG*l*2^3f=eW>F8? z1**YxPD5GM++ZS0@~AX6PAnCvXB1jGDj7_Hi9GYmbqcEc&R)p1ANwLCv$ea}CtbPIIO0^P-W z>$l~f| zyp9(2p9@D@efJdhr?krVlnY05>O4}SO868Rj&m01E@Zdzd+N^e5vsRq+;#evq1UYJ z3tye@yH#%XUb@DHQYw4YUY8FwzHQy!cXbUP>%WQl&vkw0x2yDBeF?2(Wd}tkmHRo} z7q=C*)Ytx?{zI?NS3;-Ex}9q~*sboheCiYL?z9<3ZTFB4DtwqIrFPG5sIvJ%*M%O} z$=B!>$nWX81x~D#QrUM(ce)#am#86GW@rjPKmr{E0PzI@Afz0c0TKY=s1!p000aU6 zAQS)q2*dycGYnxE00IR#qaIBnf$y&%TP(LhiXKTXI;ArKqAKE~Ndg=~;Daz_FH$+~ zMl86Q_&LUS&?6}&B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