2022-08-31 13:01:15 +00:00
|
|
|
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
|
2022-12-17 11:49:05 +00:00
|
|
|
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 {
|
2022-12-17 11:49:05 +00:00
|
|
|
err = errors.Errorf("can't find storage with rawPath: %s", rawPath)
|
|
|
|
return
|
2022-06-10 09:18:27 +00:00
|
|
|
}
|
2022-07-12 06:11:37 +00:00
|
|
|
log.Debugln("use storage: ", storage.GetStorage().MountPath)
|
2022-12-18 11:51:20 +00:00
|
|
|
mountPath := utils.GetActualMountPath(storage.GetStorage().MountPath)
|
|
|
|
actualPath = utils.FixAndCleanPath(strings.TrimPrefix(rawPath, mountPath))
|
2022-12-17 11:49:05 +00:00
|
|
|
return
|
2022-06-10 09:18:27 +00:00
|
|
|
}
|