mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-05-06 23:31:59 +08:00
perf: replace strings.Split with strings.SplitSeq (#2441)
This commit is contained in:
@@ -29,8 +29,8 @@ func getObj(img *iso9660.Image, path string) (*iso9660.File, error) {
|
||||
if path == "/" {
|
||||
return obj, nil
|
||||
}
|
||||
paths := strings.Split(strings.TrimPrefix(path, "/"), "/")
|
||||
for _, p := range paths {
|
||||
paths := strings.SplitSeq(strings.TrimPrefix(path, "/"), "/")
|
||||
for p := range paths {
|
||||
if !obj.IsDir() {
|
||||
return nil, errs.ObjectNotFound
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
stdpath "path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -490,30 +490,27 @@ func (d *downloader) checkTotalBytes(resp *http.Response) error {
|
||||
totalBytes = resp.ContentLength
|
||||
}
|
||||
} else {
|
||||
parts := strings.Split(contentRange, "/")
|
||||
|
||||
total := int64(-1)
|
||||
|
||||
// Checking for whether a numbered total exists
|
||||
// If one does not exist, we will assume the total to be -1, undefined,
|
||||
// and sequentially download each chunk until hitting a 416 error
|
||||
totalStr := parts[len(parts)-1]
|
||||
|
||||
totalStr := stdpath.Base(contentRange)
|
||||
if totalStr != "*" {
|
||||
total, err = strconv.ParseInt(totalStr, 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed extracting file size")
|
||||
if total, err := strconv.ParseInt(totalStr, 10, 64); err != nil {
|
||||
err = fmt.Errorf("failed extracting file size: %s", totalStr)
|
||||
} else {
|
||||
totalBytes = total
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf("file size unknown")
|
||||
err = fmt.Errorf("file size unknown: %s", contentRange)
|
||||
}
|
||||
|
||||
totalBytes = total
|
||||
}
|
||||
if totalBytes != d.params.Size && err == nil {
|
||||
err = fmt.Errorf("expect file size=%d unmatch remote report size=%d, need refresh cache", d.params.Size, totalBytes)
|
||||
}
|
||||
if err != nil {
|
||||
// _ = d.interrupt()
|
||||
d.setErr(err)
|
||||
d.cancel(err)
|
||||
}
|
||||
|
||||
@@ -84,8 +84,7 @@ func list(ctx context.Context, storage driver.Driver, path string, args model.Li
|
||||
|
||||
customCachePolicies := storage.GetStorage().CustomCachePolicies
|
||||
if len(customCachePolicies) > 0 {
|
||||
configPolicies := strings.Split(customCachePolicies, "\n")
|
||||
for _, configPolicy := range configPolicies {
|
||||
for configPolicy := range strings.SplitSeq(customCachePolicies, "\n") {
|
||||
pattern, ttlstr, ok := strings.Cut(strings.TrimSpace(configPolicy), ":")
|
||||
if !ok {
|
||||
log.Warnf("Malformed custom cache policy entry: %s in storage %s for path %s. Expected format: pattern:ttl", configPolicy, storage.GetStorage().MountPath, path)
|
||||
|
||||
Reference in New Issue
Block a user