refactor: split the db package hook and cache to the op package (#2747)
* refactor:separate the setting method from the db package to the op package and add the cache * refactor:separate the meta method from the db package to the op package * fix:setting not load database data * refactor:separate the user method from the db package to the op package * refactor:remove user JoinPath error * fix:op package user cache * refactor:fs package list method * fix:tile virtual paths (close #2743) * Revert "refactor:remove user JoinPath error" This reverts commit 4e20daaf9e700da047000d4fd4900abbe05c3848. * clean path directly may lead to unknown behavior * fix: The path of the meta passed in must be prefix of reqPath * chore: rename all virtualPath to mountPath * fix: `getStoragesByPath` and `GetStorageVirtualFilesByPath` is_sub_path: /a/b isn't subpath of /a/bc * fix: don't save setting if hook error Co-authored-by: Noah Hsu <i@nn.ci>
This commit is contained in:
@ -8,8 +8,8 @@ func IsBalance(str string) bool {
|
||||
return strings.Contains(str, balance)
|
||||
}
|
||||
|
||||
// GetActualVirtualPath remove balance suffix
|
||||
func GetActualVirtualPath(virtualPath string) string {
|
||||
// GetActualMountPath remove balance suffix
|
||||
func GetActualMountPath(virtualPath string) string {
|
||||
bIndex := strings.LastIndex(virtualPath, ".balance")
|
||||
if bIndex != -1 {
|
||||
virtualPath = virtualPath[:bIndex]
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"net/url"
|
||||
stdpath "path"
|
||||
"strings"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/errs"
|
||||
)
|
||||
|
||||
// FixAndCleanPath
|
||||
@ -36,6 +38,11 @@ func PathEqual(path1, path2 string) bool {
|
||||
return FixAndCleanPath(path1) == FixAndCleanPath(path2)
|
||||
}
|
||||
|
||||
func IsSubPath(path string, subPath string) bool {
|
||||
path, subPath = FixAndCleanPath(path), FixAndCleanPath(subPath)
|
||||
return path == subPath || strings.HasPrefix(path, subPath+"/")
|
||||
}
|
||||
|
||||
func Ext(path string) string {
|
||||
ext := stdpath.Ext(path)
|
||||
if strings.HasPrefix(ext, ".") {
|
||||
@ -68,5 +75,8 @@ func EncodePath(path string, all ...bool) string {
|
||||
}
|
||||
|
||||
func JoinBasePath(basePath, reqPath string) (string, error) {
|
||||
if strings.HasSuffix(reqPath, "..") || strings.Contains(reqPath, "../") {
|
||||
return "", errs.RelativePath
|
||||
}
|
||||
return stdpath.Join(FixAndCleanPath(basePath), FixAndCleanPath(reqPath)), nil
|
||||
}
|
||||
|
@ -1,5 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// SliceEqual check if two slices are equal
|
||||
func SliceEqual[T comparable](a, b []T) bool {
|
||||
if len(a) != len(b) {
|
||||
@ -44,3 +50,13 @@ func MustSliceConvert[S any, D any](srcS []S, convert func(src S) D) []D {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func MergeErrors(errs ...error) error {
|
||||
errStr := strings.Join(MustSliceConvert(errs, func(err error) string {
|
||||
return err.Error()
|
||||
}), "\n")
|
||||
if errStr != "" {
|
||||
return errors.New(errStr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user