From d3bac9a47d5bc0f57a4f8cc49b47eacbc4fbc708 Mon Sep 17 00:00:00 2001 From: hexxa Date: Wed, 25 Aug 2021 14:50:27 +0800 Subject: [PATCH] fix(files): sharing path must exactly match --- src/handlers/fileshdr/handlers.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/handlers/fileshdr/handlers.go b/src/handlers/fileshdr/handlers.go index 9ae664a..4631fd2 100644 --- a/src/handlers/fileshdr/handlers.go +++ b/src/handlers/fileshdr/handlers.go @@ -89,13 +89,13 @@ func (lk *AutoLocker) Exec(handler func()) { } // related elements: role, user, action(listing, downloading)/sharing -func (h *FileHandlers) canAccess(userName, role, op, path string) bool { +func (h *FileHandlers) canAccess(userName, role, op, sharedPath string) bool { if role == userstore.AdminRole { return true } // the file path must start with userName: /... - parts := strings.Split(path, "/") + parts := strings.Split(sharedPath, "/") if len(parts) < 2 { // the path must be longer than /files return false } else if parts[0] == userName { @@ -107,15 +107,9 @@ func (h *FileHandlers) canAccess(userName, role, op, path string) bool { if op != "list" && op != "download" { return false } - // TODO: improve performance - for i := 1; i <= len(parts); i++ { - prefix := strings.Join(parts[0:i], "/") - _, ok := h.deps.FileInfos().GetSharing(prefix) - if ok { - return true - } - } - return false + + _, ok := h.deps.FileInfos().GetSharing(sharedPath) + return ok } type CreateReq struct {