2022-08-31 21:01:15 +08:00
|
|
|
package op
|
2022-06-10 17:18:27 +08:00
|
|
|
|
|
|
|
import (
|
2022-06-15 20:31:23 +08:00
|
|
|
"strings"
|
|
|
|
|
2022-06-10 17:18:27 +08: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 14:45:39 +08:00
|
|
|
// GetStorageAndActualPath Get the corresponding storage and actual path
|
2022-08-31 22:08:12 +08:00
|
|
|
// for path: remove the mount path prefix and join the actual root folder if exists
|
2022-12-17 19:49:05 +08:00
|
|
|
func GetStorageAndActualPath(rawPath string) (storage driver.Driver, actualPath string, err error) {
|
|
|
|
rawPath = utils.FixAndCleanPath(rawPath)
|
|
|
|
storage = GetBalancedStorage(rawPath)
|
2022-07-10 14:45:39 +08:00
|
|
|
if storage == nil {
|
2022-12-17 19:49:05 +08:00
|
|
|
err = errors.Errorf("can't find storage with rawPath: %s", rawPath)
|
|
|
|
return
|
2022-06-10 17:18:27 +08:00
|
|
|
}
|
2022-07-12 14:11:37 +08:00
|
|
|
log.Debugln("use storage: ", storage.GetStorage().MountPath)
|
2022-12-18 19:51:20 +08:00
|
|
|
mountPath := utils.GetActualMountPath(storage.GetStorage().MountPath)
|
|
|
|
actualPath = utils.FixAndCleanPath(strings.TrimPrefix(rawPath, mountPath))
|
2022-12-17 19:49:05 +08:00
|
|
|
return
|
2022-06-10 17:18:27 +08:00
|
|
|
}
|