From 7dc52017937aaad370066dcdf59abbb0af5005f6 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Thu, 21 Oct 2021 17:02:01 +0200 Subject: [PATCH] Fixes --- internal/http/services/owncloud/ocs/cache.go | 14 +++++++------- .../ocs/handlers/apps/sharing/shares/shares.go | 11 ++++------- internal/http/services/owncloud/ocs/ocs.go | 12 ++++++------ pkg/storage/utils/eosfs/eosfs.go | 3 --- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/internal/http/services/owncloud/ocs/cache.go b/internal/http/services/owncloud/ocs/cache.go index fb1539a9f5..2db8e33702 100644 --- a/internal/http/services/owncloud/ocs/cache.go +++ b/internal/http/services/owncloud/ocs/cache.go @@ -28,7 +28,7 @@ import ( ) func (s *svc) cacheWarmup(w http.ResponseWriter, r *http.Request) { - if s.warmupCache != nil { + if s.warmupCacheTracker != nil { u := ctxpkg.ContextMustGetUser(r.Context()) tkn := ctxpkg.ContextMustGetToken(r.Context()) @@ -40,13 +40,13 @@ func (s *svc) cacheWarmup(w http.ResponseWriter, r *http.Request) { req.Method = http.MethodGet id := u.Id.OpaqueId - if _, err := s.warmupCache.Get(id); err != nil { + if _, err := s.warmupCacheTracker.Get(id); err != nil { p := httptest.NewRecorder() - _ = s.warmupCache.Set(id, true) - req.URL.Path = "/apps/files_sharing/api/v1/shares" - go s.router.ServeHTTP(p, req) - req.URL.Path = "/apps/files_sharing/api/v1/shares?shared_with_me=true" - go s.router.ServeHTTP(p, req) + _ = s.warmupCacheTracker.Set(id, true) + req.URL.Path = "/v1.php/apps/files_sharing/api/v1/shares" + s.router.ServeHTTP(p, req) + req.URL.Path = "/v1.php/apps/files_sharing/api/v1/shares?shared_with_me=true" + s.router.ServeHTTP(p, req) } } } diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go index 0a46ce49a4..47bc328efb 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go @@ -494,11 +494,11 @@ func (h *Handler) ListShares(w http.ResponseWriter, r *http.Request) { response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error mapping share data", err) } if listSharedWithMe { - h.ListSharesWithMe(w, r) + h.listSharesWithMe(w, r) return } } - h.ListSharesWithOthers(w, r) + h.listSharesWithOthers(w, r) } const ( @@ -508,8 +508,7 @@ const ( ocsStateRejected = 2 ) -// ListSharesWithMe returns the shares receieved by the user present in the context -func (h *Handler) ListSharesWithMe(w http.ResponseWriter, r *http.Request) { +func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { // which pending state to list stateFilter := getStateFilter(r.FormValue("state")) @@ -706,9 +705,7 @@ func findMatch(shareJailInfos []*provider.ResourceInfo, id *provider.ResourceId) return nil } -// ListSharesWithOthers returns the public, user, group and federated shares -// created by the user present in the context -func (h *Handler) ListSharesWithOthers(w http.ResponseWriter, r *http.Request) { +func (h *Handler) listSharesWithOthers(w http.ResponseWriter, r *http.Request) { shares := make([]*conversions.ShareData, 0) filters := []*collaboration.Filter{} diff --git a/internal/http/services/owncloud/ocs/ocs.go b/internal/http/services/owncloud/ocs/ocs.go index 91c2b824de..d411f4dace 100644 --- a/internal/http/services/owncloud/ocs/ocs.go +++ b/internal/http/services/owncloud/ocs/ocs.go @@ -43,9 +43,9 @@ func init() { } type svc struct { - c *config.Config - router *chi.Mux - warmupCache *ttlcache.Cache + c *config.Config + router *chi.Mux + warmupCacheTracker *ttlcache.Cache } func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error) { @@ -67,8 +67,8 @@ func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error) } if conf.CacheWarmupDriver == "first-request" && conf.ResourceInfoCacheTTL > 0 { - s.warmupCache = ttlcache.NewCache() - _ = s.warmupCache.SetTTL(time.Second * time.Duration(conf.ResourceInfoCacheTTL)) + s.warmupCacheTracker = ttlcache.NewCache() + _ = s.warmupCacheTracker.SetTTL(time.Second * time.Duration(conf.ResourceInfoCacheTTL)) } return s, nil @@ -148,7 +148,7 @@ func (s *svc) Handler() http.Handler { log.Debug().Str("path", r.URL.Path).Msg("ocs routing") // Warmup the share cache for the user - s.cacheWarmup(w, r) + go s.cacheWarmup(w, r) // unset raw path, otherwise chi uses it to route and then fails to match percent encoded path segments r.URL.RawPath = "" diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index 702b703ef1..da5012e22e 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -1771,9 +1771,6 @@ func getResourceType(isDir bool) provider.ResourceType { } func (fs *eosfs) extractUIDAndGID(u *userpb.User) (eosclient.Authorization, error) { - if u.Id.OpaqueId == "root" { - return eosclient.Authorization{Role: eosclient.Role{UID: "0", GID: "0"}}, nil - } if u.UidNumber == 0 { return eosclient.Authorization{}, errors.New("eosfs: uid missing for user") }