|
@@ -2,8 +2,6 @@ package user
|
|
|
|
|
|
import (
|
|
import (
|
|
"errors"
|
|
"errors"
|
|
- "path/filepath"
|
|
|
|
- "strings"
|
|
|
|
|
|
|
|
fs "imuslab.com/arozos/mod/filesystem"
|
|
fs "imuslab.com/arozos/mod/filesystem"
|
|
)
|
|
)
|
|
@@ -12,7 +10,7 @@ import (
|
|
Private functions
|
|
Private functions
|
|
*/
|
|
*/
|
|
|
|
|
|
-//Get a fs handler from a virtual path, quick function for getIDFromHandler + GetHandlerFromID
|
|
|
|
|
|
+// Get a fs handler from a virtual path, quick function for getIDFromHandler + GetHandlerFromID
|
|
func getHandlerFromVirtualPath(storages []*fs.FileSystemHandler, vpath string) (*fs.FileSystemHandler, error) {
|
|
func getHandlerFromVirtualPath(storages []*fs.FileSystemHandler, vpath string) (*fs.FileSystemHandler, error) {
|
|
vid, _, err := getIDFromVirtualPath(vpath)
|
|
vid, _, err := getIDFromVirtualPath(vpath)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -22,7 +20,7 @@ func getHandlerFromVirtualPath(storages []*fs.FileSystemHandler, vpath string) (
|
|
return getHandlerFromID(storages, vid)
|
|
return getHandlerFromID(storages, vid)
|
|
}
|
|
}
|
|
|
|
|
|
-//Get a fs handler from the given virtial device id
|
|
|
|
|
|
+// Get a fs handler from the given virtial device id
|
|
func getHandlerFromID(storages []*fs.FileSystemHandler, vid string) (*fs.FileSystemHandler, error) {
|
|
func getHandlerFromID(storages []*fs.FileSystemHandler, vid string) (*fs.FileSystemHandler, error) {
|
|
for _, storage := range storages {
|
|
for _, storage := range storages {
|
|
if storage.UUID == vid {
|
|
if storage.UUID == vid {
|
|
@@ -34,19 +32,7 @@ func getHandlerFromID(storages []*fs.FileSystemHandler, vid string) (*fs.FileSys
|
|
return &fs.FileSystemHandler{}, errors.New("handler Not Found")
|
|
return &fs.FileSystemHandler{}, errors.New("handler Not Found")
|
|
}
|
|
}
|
|
|
|
|
|
-//Get the ID part of a virtual path, return ID, subpath and error
|
|
|
|
|
|
+// Get the ID part of a virtual path, return ID, subpath and error
|
|
func getIDFromVirtualPath(vpath string) (string, string, error) {
|
|
func getIDFromVirtualPath(vpath string) (string, string, error) {
|
|
- if !strings.Contains(vpath, ":") {
|
|
|
|
- return "", "", errors.New("path missing Virtual Device ID. Given: " + vpath)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //Clean up the virutal path
|
|
|
|
- vpath = filepath.ToSlash(filepath.Clean(vpath))
|
|
|
|
-
|
|
|
|
- tmp := strings.Split(vpath, ":")
|
|
|
|
- vdID := tmp[0]
|
|
|
|
- pathSlice := tmp[1:]
|
|
|
|
- path := strings.Join(pathSlice, ":")
|
|
|
|
-
|
|
|
|
- return vdID, path, nil
|
|
|
|
|
|
+ return fs.GetIDFromVirtualPath(vpath)
|
|
}
|
|
}
|