From b09d4d5d69ef8bfb7c75ccc2a15af25aa0dafa37 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 28 Jan 2026 01:13:56 -0800 Subject: [PATCH] s3tables: replace custom splitPath with stdlib functions - Remove custom splitPath implementation (23 lines) - Use filepath.Dir and filepath.Base from stdlib - More robust and handles edge cases correctly - Reduces code duplication --- weed/s3api/s3tables/utils.go | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/weed/s3api/s3tables/utils.go b/weed/s3api/s3tables/utils.go index a2eacbfe5..b796a1d09 100644 --- a/weed/s3api/s3tables/utils.go +++ b/weed/s3api/s3tables/utils.go @@ -2,6 +2,7 @@ package s3tables import ( "fmt" + "path/filepath" "regexp" "time" ) @@ -90,27 +91,9 @@ func generateVersionToken() string { return fmt.Sprintf("%d", time.Now().UnixNano()) } -// splitPath splits a path into directory and name components +// splitPath splits a path into directory and name components using stdlib func splitPath(path string) (dir, name string) { - var idx int - var i int - - // Remove trailing slash - for i = len(path) - 1; i >= 0 && path[i] == '/'; i-- { - } - path = path[:i+1] - - // Find last separator - idx = len(path) - 1 - for idx >= 0 && path[idx] != '/' { - idx-- - } - - if idx == -1 { - return "/", path - } - if idx == 0 { - return "/", path[1:] - } - return path[:idx], path[idx+1:] + dir = filepath.Dir(path) + name = filepath.Base(path) + return }