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
This commit is contained in:
@@ -2,6 +2,7 @@ package s3tables
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -90,27 +91,9 @@ func generateVersionToken() string {
|
|||||||
return fmt.Sprintf("%d", time.Now().UnixNano())
|
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) {
|
func splitPath(path string) (dir, name string) {
|
||||||
var idx int
|
dir = filepath.Dir(path)
|
||||||
var i int
|
name = filepath.Base(path)
|
||||||
|
return
|
||||||
// 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:]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user