From 614cb479599ca89e0b15b8584b83b986d58f7bc0 Mon Sep 17 00:00:00 2001 From: Rosie Kern Date: Wed, 30 Oct 2024 14:23:47 +0000 Subject: [PATCH] Fix subDirs not haveing the correct age --- go.mod | 2 ++ server/basedirs.go | 54 +++++++++++++++++----------- server/server_test.go | 11 ++++++ server/static/wrstat/src/App.tsx | 1 + server/static/wrstat/src/SubDirs.tsx | 7 ++-- 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index ba43e55..ddc8e6a 100644 --- a/go.mod +++ b/go.mod @@ -171,3 +171,5 @@ replace github.com/docker/spdystream => github.com/docker/spdystream v0.1.0 // mergo moved to a vanity URL in v1.0.0 replace github.com/imdario/mergo => github.com/imdario/mergo v0.3.16 + +replace github.com/wtsi-ssg/wrstat/v5 => /nfs/users/nfs_r/rk18/src/wrstat diff --git a/server/basedirs.go b/server/basedirs.go index b864c90..eb18a29 100644 --- a/server/basedirs.go +++ b/server/basedirs.go @@ -151,7 +151,7 @@ func (s *Server) getBasedirsGroupSubdirs(c *gin.Context) { return } - id, basedir, ok := getSubdirsArgs(c) + id, basedir, age, ok := getSubdirsArgs(c) if !ok { return } @@ -165,41 +165,53 @@ func (s *Server) getBasedirsGroupSubdirs(c *gin.Context) { s.getBasedirs(c, func() (any, error) { var results []*basedirs.SubDir - for _, age := range summary.DirGUTAges { - result, err := s.basedirs.GroupSubDirs(uint32(id), basedir, age) - if err != nil { - return nil, err - } - - results = append(results, result...) + // for _, age := range summary.DirGUTAges { + result, err := s.basedirs.GroupSubDirs(uint32(id), basedir, age) + if err != nil { + return nil, err } + results = append(results, result...) + // } + return results, nil }) } -func getSubdirsArgs(c *gin.Context) (int, string, bool) { +func getSubdirsArgs(c *gin.Context) (int, string, summary.DirGUTAge, bool) { idStr := c.Query("id") basedir := c.Query("basedir") + ageStr := c.Query("age") if idStr == "" || basedir == "" { c.AbortWithError(http.StatusBadRequest, ErrBadBasedirsQuery) //nolint:errcheck - return 0, "", false + return 0, "", summary.DGUTAgeAll, false } id, err := strconv.Atoi(idStr) if err != nil { c.AbortWithError(http.StatusBadRequest, ErrBadBasedirsQuery) //nolint:errcheck - return 0, "", false + return 0, "", summary.DGUTAgeAll, false + } + + if ageStr == "" { + ageStr = "0" } - return id, basedir, true + age, err := summary.AgeStringToDirGUTAge(ageStr) + if err != nil { + c.AbortWithError(http.StatusBadRequest, ErrBadBasedirsQuery) //nolint:errcheck + + return 0, "", summary.DGUTAgeAll, false + } + + return id, basedir, age, true } func (s *Server) getBasedirsUserSubdirs(c *gin.Context) { - id, basedir, ok := getSubdirsArgs(c) + id, basedir, age, ok := getSubdirsArgs(c) if !ok { return } @@ -213,15 +225,15 @@ func (s *Server) getBasedirsUserSubdirs(c *gin.Context) { s.getBasedirs(c, func() (any, error) { var results []*basedirs.SubDir - for _, age := range summary.DirGUTAges { - result, err := s.basedirs.UserSubDirs(uint32(id), basedir, age) - if err != nil { - return nil, err - } - - results = append(results, result...) + // for _, age := range summary.DirGUTAges { + result, err := s.basedirs.UserSubDirs(uint32(id), basedir, age) + if err != nil { + return nil, err } + results = append(results, result...) + // } + return results, nil }) } @@ -248,7 +260,7 @@ func (s *Server) isUserAuthedToReadPath(c *gin.Context, path string) bool { } func (s *Server) getBasedirsHistory(c *gin.Context) { - id, basedir, ok := getSubdirsArgs(c) + id, basedir, _, ok := getSubdirsArgs(c) if !ok { return } diff --git a/server/server_test.go b/server/server_test.go index 26253d0..8cea19d 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -688,6 +688,17 @@ func TestServer(t *testing.T) { So(len(history), ShouldEqual, 1) So(history[0].UsageInodes, ShouldEqual, 2) + response, err = query(s, EndPointBasedirSubdirUser, + fmt.Sprintf("?id=%d&basedir=%s&age=%d", usageUser[0].UID, usageUser[0].BaseDir, summary.DGUTAgeA3Y)) + So(err, ShouldBeNil) + So(response.Code, ShouldEqual, http.StatusOK) + So(logWriter.String(), ShouldContainSubstring, "[GET /rest/v1/basedirs/subdirs/user") + So(logWriter.String(), ShouldContainSubstring, "STATUS=200") + + subdirs, err = decodeSubdirResult(response) + So(err, ShouldBeNil) + So(len(subdirs), ShouldEqual, 17) + Convey("Which get updated by an auto-reload when the sentinal file changes", func() { parentDir := filepath.Dir(filepath.Dir(dbPath)) sentinel := filepath.Join(parentDir, ".sentinel") diff --git a/server/static/wrstat/src/App.tsx b/server/static/wrstat/src/App.tsx index b6a2b25..81b39dd 100644 --- a/server/static/wrstat/src/App.tsx +++ b/server/static/wrstat/src/App.tsx @@ -254,6 +254,7 @@ const groupNameToIDMap = new Map(), sub === "." ? base : base + "/" sortNumFiles = (a: SubDir, b: SubDir) => a.NumFiles - b.NumFiles, sortSizeFiles = (a: SubDir, b: SubDir) => a.SizeFiles - b.SizeFiles, sortLastModifed = (a: SubDir, b: SubDir) => new Date(b.LastModified).valueOf() - new Date(a.LastModified).valueOf(), - SubdirsComponent = ({ id, path, isUser, treePath, setTreePath, justDisktree }: SubDirParams) => { + SubdirsComponent = ({ id, path, age, isUser, treePath, setTreePath, justDisktree }: SubDirParams) => { const [subdirs, setSubdirs] = useState([]); useEffect(() => { @@ -74,9 +75,9 @@ const pathJoin = (base: string, sub: string) => sub === "." ? base : base + "/" return; } - (isUser ? RPC.getBasedirsUserSubdirs : RPC.getBasedirsGroupSubdirs)(id, path) + (isUser ? RPC.getBasedirsUserSubdirs : RPC.getBasedirsGroupSubdirs)(id, path, age) .then(setSubdirs); - }, [id, path, isUser]); + }, [id, path, age, isUser]); if (!subdirs || subdirs.length === 0) { return <>;