|
@@ -13,28 +13,44 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
type RootRouter struct {
|
|
type RootRouter struct {
|
|
- parent *Server
|
|
|
|
|
|
+ pathPrefix string
|
|
|
|
+ parent *Server
|
|
}
|
|
}
|
|
|
|
|
|
// InitiateRootRouter create and prepare a virtual root file system for
|
|
// InitiateRootRouter create and prepare a virtual root file system for
|
|
// this bokoFS instance
|
|
// this bokoFS instance
|
|
func (s *Server) InitiateRootRouter() error {
|
|
func (s *Server) InitiateRootRouter() error {
|
|
s.RootRouter = &RootRouter{
|
|
s.RootRouter = &RootRouter{
|
|
- parent: s,
|
|
|
|
|
|
+ pathPrefix: s.prefix,
|
|
|
|
+ parent: s,
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// fixpath fix the path to be relative to the root path of this router
|
|
|
|
+func (r *RootRouter) fixpath(name string) string {
|
|
|
|
+ if name == r.pathPrefix || name == "" {
|
|
|
|
+ return "/"
|
|
|
|
+ }
|
|
|
|
+ //Trim off the prefix path
|
|
|
|
+ name = strings.TrimPrefix(name, r.pathPrefix)
|
|
|
|
+ if !strings.HasPrefix(name, "/") {
|
|
|
|
+ name = "/" + name
|
|
|
|
+ }
|
|
|
|
+ return name
|
|
|
|
+}
|
|
|
|
+
|
|
func (r *RootRouter) GetRootDir(name string) string {
|
|
func (r *RootRouter) GetRootDir(name string) string {
|
|
- if name == "" {
|
|
|
|
|
|
+ if name == "" || name == "/" {
|
|
return "/"
|
|
return "/"
|
|
}
|
|
}
|
|
|
|
+
|
|
name = filepath.ToSlash(filepath.Clean(name))
|
|
name = filepath.ToSlash(filepath.Clean(name))
|
|
pathChunks := strings.Split(name, "/")
|
|
pathChunks := strings.Split(name, "/")
|
|
reqRootPath := "/" + pathChunks[1]
|
|
reqRootPath := "/" + pathChunks[1]
|
|
fmt.Println("Requesting Root Path: ", reqRootPath)
|
|
fmt.Println("Requesting Root Path: ", reqRootPath)
|
|
- reqRootPath = strings.TrimSuffix(reqRootPath, "/")
|
|
|
|
- return reqRootPath
|
|
|
|
|
|
+ name = strings.TrimSuffix(reqRootPath, "/")
|
|
|
|
+ return name
|
|
}
|
|
}
|
|
|
|
|
|
func (r *RootRouter) GetWorkerByPath(name string) (*bokoworker.Worker, error) {
|
|
func (r *RootRouter) GetWorkerByPath(name string) (*bokoworker.Worker, error) {
|
|
@@ -49,12 +65,14 @@ func (r *RootRouter) GetWorkerByPath(name string) (*bokoworker.Worker, error) {
|
|
|
|
|
|
func (r *RootRouter) Mkdir(ctx context.Context, name string, perm os.FileMode) error {
|
|
func (r *RootRouter) Mkdir(ctx context.Context, name string, perm os.FileMode) error {
|
|
// Implement the Mkdir method
|
|
// Implement the Mkdir method
|
|
|
|
+ name = r.fixpath(name)
|
|
fmt.Println("Mkdir called to " + name)
|
|
fmt.Println("Mkdir called to " + name)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
func (r *RootRouter) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error) {
|
|
func (r *RootRouter) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error) {
|
|
// Implement the OpenFile method
|
|
// Implement the OpenFile method
|
|
|
|
+ name = r.fixpath(name)
|
|
fmt.Println("OpenFile called to " + name)
|
|
fmt.Println("OpenFile called to " + name)
|
|
if filepath.ToSlash(filepath.Base(name)) == "/" {
|
|
if filepath.ToSlash(filepath.Base(name)) == "/" {
|
|
//Request to the vObject base path
|
|
//Request to the vObject base path
|
|
@@ -79,20 +97,25 @@ func (r *RootRouter) OpenFile(ctx context.Context, name string, flag int, perm o
|
|
|
|
|
|
func (r *RootRouter) RemoveAll(ctx context.Context, name string) error {
|
|
func (r *RootRouter) RemoveAll(ctx context.Context, name string) error {
|
|
// Implement the RemoveAll method
|
|
// Implement the RemoveAll method
|
|
|
|
+ name = r.fixpath(name)
|
|
fmt.Println("RemoveAll called to " + name)
|
|
fmt.Println("RemoveAll called to " + name)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
func (r *RootRouter) Rename(ctx context.Context, oldName, newName string) error {
|
|
func (r *RootRouter) Rename(ctx context.Context, oldName, newName string) error {
|
|
// Implement the Rename method
|
|
// Implement the Rename method
|
|
|
|
+ oldName = r.fixpath(oldName)
|
|
|
|
+ newName = r.fixpath(newName)
|
|
fmt.Println("Rename called from " + oldName + " to " + newName)
|
|
fmt.Println("Rename called from " + oldName + " to " + newName)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
func (r *RootRouter) Stat(ctx context.Context, name string) (os.FileInfo, error) {
|
|
func (r *RootRouter) Stat(ctx context.Context, name string) (os.FileInfo, error) {
|
|
// Implement the Stat method
|
|
// Implement the Stat method
|
|
|
|
+ name = r.fixpath(name)
|
|
fmt.Println("Stat called to " + name)
|
|
fmt.Println("Stat called to " + name)
|
|
if filepath.ToSlash(filepath.Base(name)) == "/" {
|
|
if filepath.ToSlash(filepath.Base(name)) == "/" {
|
|
|
|
+ //Create an emulated file system to serve the mounted workers
|
|
thisVirtualObject := r.newVirtualObject(&vObjectProperties{
|
|
thisVirtualObject := r.newVirtualObject(&vObjectProperties{
|
|
name: name,
|
|
name: name,
|
|
size: 0,
|
|
size: 0,
|
|
@@ -106,7 +129,9 @@ func (r *RootRouter) Stat(ctx context.Context, name string) (os.FileInfo, error)
|
|
return thisVirtualObjectFileInfo, nil
|
|
return thisVirtualObjectFileInfo, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //Load the target worker from the path
|
|
targetWorker, err := r.GetWorkerByPath(name)
|
|
targetWorker, err := r.GetWorkerByPath(name)
|
|
|
|
+ fmt.Println("Target Worker: ", targetWorker, name)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|