Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions drivers/lenovonas_share/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
stdpath "path"
"strings"
"time"

Expand Down Expand Up @@ -32,6 +33,7 @@ func (d *LenovoNasShare) GetAddition() driver.Additional {
}

func (d *LenovoNasShare) Init(ctx context.Context) error {
d.ShareId = stdpath.Base(d.ShareId)
if err := d.getStoken(); err != nil {
return err
}
Expand Down Expand Up @@ -98,9 +100,6 @@ func (d *LenovoNasShare) getStoken() error { // 获取stoken
d.Host = "https://siot-share.lenovo.com.cn"
}

parts := strings.Split(d.ShareId, "/")
d.ShareId = parts[len(parts)-1]

query := map[string]string{
"code": d.ShareId,
"password": d.SharePwd,
Expand Down
12 changes: 6 additions & 6 deletions drivers/strm/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (d *Strm) Init(ctx context.Context) error {
return errors.New("SaveStrmLocalPath is required")
}
d.pathMap = make(map[string][]string)
for _, path := range strings.Split(d.Paths, "\n") {
for path := range strings.SplitSeq(d.Paths, "\n") {
path = strings.TrimSpace(path)
if path == "" {
continue
Expand Down Expand Up @@ -97,17 +97,17 @@ func (d *Strm) Init(ctx context.Context) error {
}

if d.Version != 5 {
types := strings.Split("mp4,mkv,flv,avi,wmv,ts,rmvb,webm,mp3,flac,aac,wav,ogg,m4a,wma,alac", ",")
for _, ext := range types {
types := strings.SplitSeq("mp4,mkv,flv,avi,wmv,ts,rmvb,webm,mp3,flac,aac,wav,ogg,m4a,wma,alac", ",")
for ext := range types {
if _, ok := d.supportSuffix[ext]; !ok {
d.supportSuffix[ext] = struct{}{}
supportTypes = append(supportTypes, ext)
}
}
d.FilterFileTypes = strings.Join(supportTypes, ",")

types = strings.Split("ass,srt,vtt,sub,strm", ",")
for _, ext := range types {
types = strings.SplitSeq("ass,srt,vtt,sub,strm", ",")
for ext := range types {
if _, ok := d.downloadSuffix[ext]; !ok {
d.downloadSuffix[ext] = struct{}{}
downloadTypes = append(downloadTypes, ext)
Expand All @@ -127,7 +127,7 @@ func (d *Strm) Drop(ctx context.Context) error {
d.pathMap = nil
d.downloadSuffix = nil
d.supportSuffix = nil
for _, path := range strings.Split(d.Paths, "\n") {
for path := range strings.SplitSeq(d.Paths, "\n") {
RemoveStrm(utils.FixAndCleanPath(strings.TrimSpace(path)), d)
}
return nil
Expand Down
7 changes: 2 additions & 5 deletions drivers/url_tree/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ import (
*/
// if there are no name, use the last segment of url as name
func BuildTree(text string, headSize bool) (*Node, error) {
lines := strings.Split(text, "\n")
var root = &Node{Level: -1, Name: "root"}
stack := []*Node{root}
for _, line := range lines {
for line := range strings.SplitSeq(text, "\n") {
// calculate indent
indent := 0
for i := 0; i < len(line); i++ {
Expand Down Expand Up @@ -153,9 +152,7 @@ func splitPath(path string) []string {
if path == "/" {
return []string{"root"}
}
if strings.HasSuffix(path, "/") {
path = path[:len(path)-1]
}
path = strings.TrimSuffix(path, "/")
parts := strings.Split(path, "/")
parts[0] = "root"
return parts
Expand Down
3 changes: 1 addition & 2 deletions drivers/webdav/odrvcookie/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ func getLoginUrl(endpoint string) (string, error) {
if err != nil {
return "", err
}
domains := strings.Split(spRoot.Host, ".")
tld := domains[len(domains)-1]
tld := spRoot.Host[strings.LastIndex(spRoot.Host, ".")+1:]
loginUrl, ok := loginUrlsMap[tld]
if !ok {
return "", fmt.Errorf("tld %s is not supported", tld)
Expand Down
4 changes: 2 additions & 2 deletions internal/archive/iso9660/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 8 additions & 11 deletions internal/net/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"io"
"net/http"
stdpath "path"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/op/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/gowebdav/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ func (c *Client) MkdirAll(path string, _ os.FileMode) (err error) {
return nil
}
if status == 409 {
paths := strings.Split(path, "/")
paths := strings.SplitSeq(path, "/")
sub := "/"
for _, e := range paths {
for e := range paths {
if e == "" {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/gowebdav/digestAuth.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func digestParts(resp *http.Response) map[string]string {
result := map[string]string{}
if len(resp.Header["Www-Authenticate"]) > 0 {
wantedHeaders := []string{"nonce", "realm", "qop", "opaque", "algorithm", "entityBody"}
responseHeaders := strings.Split(resp.Header["Www-Authenticate"][0], ",")
for _, r := range responseHeaders {
responseHeaders := strings.SplitSeq(resp.Header["Www-Authenticate"][0], ",")
for r := range responseHeaders {
for _, w := range wantedHeaders {
if strings.Contains(r, w) {
result[w] = strings.Trim(
Expand Down
8 changes: 4 additions & 4 deletions pkg/http_range/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ func ParseRange(s string, size int64) ([]Range, error) { // nolint:gocognit
}
var ranges []Range
noOverlap := false
for _, ra := range strings.Split(s[len(b):], ",") {
for ra := range strings.SplitSeq(s[len(b):], ",") {
ra = textproto.TrimString(ra)
if ra == "" {
continue
}
i := strings.Index(ra, "-")
if i < 0 {
before, after, ok := strings.Cut(ra, "-")
if !ok {
return nil, ErrInvalid
}
start, end := textproto.TrimString(ra[:i]), textproto.TrimString(ra[i+1:])
start, end := textproto.TrimString(before), textproto.TrimString(after)
var r Range
if start == "" {
// If no start is specified, end specifies the
Expand Down
8 changes: 4 additions & 4 deletions pkg/sign/hmac.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func (s HMACSign) Sign(data string, expire int64) string {
}

func (s HMACSign) Verify(data, sign string) error {
signSlice := strings.Split(sign, ":")
// check whether contains expire time
if signSlice[len(signSlice)-1] == "" {
// check whether contains exp time
exp := sign[strings.LastIndex(sign, ":")+1:]
if exp == "" {
return ErrExpireMissing
}
// check whether expire time is expired
expires, err := strconv.ParseInt(signSlice[len(signSlice)-1], 10, 64)
expires, err := strconv.ParseInt(exp, 10, 64)
if err != nil {
return ErrExpireInvalid
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/utils/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ func GetPathHierarchy(path string) []string {

hierarchy := []string{"/"}

parts := strings.Split(path, "/")
currentPath := ""
for _, part := range parts {
parts := strings.SplitSeq(path, "/")
var currentPath strings.Builder
for part := range parts {
if part == "" {
continue
}
currentPath += "/" + part
hierarchy = append(hierarchy, currentPath)
currentPath.WriteString("/" + part)
hierarchy = append(hierarchy, currentPath.String())
}

return hierarchy
Expand Down
2 changes: 1 addition & 1 deletion server/common/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func CanAccess(user *model.User, meta *model.Meta, reqPath string, password stri
// if the reqPath is in hide (only can check the nearest meta) and user can't see hides, can't access
if meta != nil && !user.CanSeeHides() && meta.Hide != "" &&
MetaCoversPath(meta.Path, path.Dir(reqPath), meta.HSub) { // the meta should apply to the parent of current path
for _, hide := range strings.Split(meta.Hide, "\n") {
for hide := range strings.SplitSeq(meta.Hide, "\n") {
re := regexp2.MustCompile(hide, regexp2.None)
if isMatch, _ := re.MatchString(path.Base(reqPath)); isMatch {
return false
Expand Down
2 changes: 1 addition & 1 deletion server/ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func newPortMapper(str string) ftpserver.PasvPortGetter {
if str == "" {
return nil
}
pasvPortMappers := strings.Split(strings.Replace(str, "\n", ",", -1), ",")
pasvPortMappers := strings.Split(strings.ReplaceAll(str, "\n", ","), ",")
groups := make([]group, len(pasvPortMappers))
totalLength := 0
convertToPorts := func(str string) (int, int, error) {
Expand Down
4 changes: 2 additions & 2 deletions server/handles/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func UpdateMeta(c *gin.Context) {
}

func validHide(hide string) (string, error) {
rs := strings.Split(hide, "\n")
for _, r := range rs {
rs := strings.SplitSeq(hide, "\n")
for r := range rs {
_, err := regexp2.Compile(r, regexp2.None)
if err != nil {
return r, err
Expand Down
Loading