alist/internal/op/path.go

26 lines
848 B
Go
Raw Normal View History

package op
2022-06-10 09:18:27 +00:00
import (
2022-06-15 12:31:23 +00:00
"strings"
2022-06-10 09:18:27 +00:00
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
2022-07-10 06:45:39 +00:00
// GetStorageAndActualPath Get the corresponding storage and actual path
2022-08-31 14:08:12 +00:00
// for path: remove the mount path prefix and join the actual root folder if exists
func GetStorageAndActualPath(rawPath string) (storage driver.Driver, actualPath string, err error) {
rawPath = utils.FixAndCleanPath(rawPath)
storage = GetBalancedStorage(rawPath)
2022-07-10 06:45:39 +00:00
if storage == nil {
err = errors.Errorf("can't find storage with rawPath: %s", rawPath)
return
2022-06-10 09:18:27 +00:00
}
log.Debugln("use storage: ", storage.GetStorage().MountPath)
mountPath := utils.GetActualMountPath(storage.GetStorage().MountPath)
actualPath = utils.FixAndCleanPath(strings.TrimPrefix(rawPath, mountPath))
return
2022-06-10 09:18:27 +00:00
}