internal.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package user
  2. import (
  3. "errors"
  4. fs "imuslab.com/arozos/mod/filesystem"
  5. )
  6. /*
  7. Private functions
  8. */
  9. // Get a fs handler from a virtual path, quick function for getIDFromHandler + GetHandlerFromID
  10. func getHandlerFromVirtualPath(storages []*fs.FileSystemHandler, vpath string) (*fs.FileSystemHandler, error) {
  11. vid, _, err := getIDFromVirtualPath(vpath)
  12. if err != nil {
  13. return &fs.FileSystemHandler{}, err
  14. }
  15. return getHandlerFromID(storages, vid)
  16. }
  17. // Get a fs handler from the given virtial device id
  18. func getHandlerFromID(storages []*fs.FileSystemHandler, vid string) (*fs.FileSystemHandler, error) {
  19. for _, storage := range storages {
  20. if storage.UUID == vid {
  21. //This storage is the one we are looking at
  22. return storage, nil
  23. }
  24. }
  25. return &fs.FileSystemHandler{}, errors.New("handler Not Found")
  26. }
  27. // Get the ID part of a virtual path, return ID, subpath and error
  28. func getIDFromVirtualPath(vpath string) (string, string, error) {
  29. return fs.GetIDFromVirtualPath(vpath)
  30. }