Jelajahi Sumber

Removed share vroot

tobychui 3 tahun lalu
induk
melakukan
8f34ecc02b

+ 133 - 198
file_system.go

@@ -188,6 +188,7 @@ func FileSystemInit() {
 	router.HandleFunc("/system/file_system/share/delete", shareManager.HandleDeleteShare)
 	router.HandleFunc("/system/file_system/share/edit", shareManager.HandleEditShare)
 	router.HandleFunc("/system/file_system/share/checkShared", shareManager.HandleShareCheck)
+	router.HandleFunc("/system/file_system/share/list", shareManager.HandleListAllShares)
 
 	//Handle the main share function
 	//Share function is now routed by the main router
@@ -250,7 +251,7 @@ func system_fs_handleFileSearch(w http.ResponseWriter, r *http.Request) {
 	//Check if case sensitive is enabled
 	casesensitve, _ := common.Mv(r, "casesensitive", true)
 
-	vrootID, subpath, err := fs.GetIDFromVirtualPath(vpath)
+	vrootID, _, err := fs.GetIDFromVirtualPath(vpath)
 	var targetFSH *filesystem.FileSystemHandler = nil
 	if err != nil {
 		common.SendErrorResponse(w, "Invalid path given")
@@ -317,44 +318,24 @@ func system_fs_handleFileSearch(w http.ResponseWriter, r *http.Request) {
 		//Recursive keyword
 		results := []fs.FileData{}
 		var err error = nil
-		if targetFSH != nil && targetFSH.UUID == "share" {
-			//To be done: Move hardcoded vroot ID to interface for all virtual storage devices
+
+		fshAbs := targetFSH.FileSystemAbstraction
+		err = fshAbs.Walk(rpath, func(path string, info os.FileInfo, err error) error {
+			thisFilename := filepath.Base(path)
 			if casesensitve != "true" {
-				keyword = strings.ToLower(keyword)
+				thisFilename = strings.ToLower(thisFilename)
 			}
-			err = shareManager.Walk(subpath, userinfo, func(fileData fs.FileData) error {
-				filename := filepath.Base(fileData.Filename)
-				if casesensitve != "true" {
-					filename = strings.ToLower(filename)
-				}
-				if matcher.Match(filename) {
-					//This is a matching file
-					if !fs.IsInsideHiddenFolder(fileData.Filepath) {
-						results = append(results, fileData)
-					}
-				}
-				return nil
-			})
 
-		} else {
-			fshAbs := targetFSH.FileSystemAbstraction
-			err = fshAbs.Walk(rpath, func(path string, info os.FileInfo, err error) error {
-				thisFilename := filepath.Base(path)
-				if casesensitve != "true" {
-					thisFilename = strings.ToLower(thisFilename)
-				}
-
-				if !fs.IsInsideHiddenFolder(path) {
-					if matcher.Match(thisFilename) {
-						//This is a matching file
-						thisVpath, _ := fshAbs.RealPathToVirtualPath(path, userinfo.Username)
-						results = append(results, fs.GetFileDataFromPath(targetFSH, thisVpath, path, 2))
-					}
+			if !fs.IsInsideHiddenFolder(path) {
+				if matcher.Match(thisFilename) {
+					//This is a matching file
+					thisVpath, _ := fshAbs.RealPathToVirtualPath(path, userinfo.Username)
+					results = append(results, fs.GetFileDataFromPath(targetFSH, thisVpath, path, 2))
 				}
+			}
 
-				return nil
-			})
-		}
+			return nil
+		})
 
 		if err != nil {
 			common.SendErrorResponse(w, err.Error())
@@ -2238,13 +2219,6 @@ func system_fs_listRoot(w http.ResponseWriter, r *http.Request) {
 			} else if store.Hierarchy == "backup" {
 				//Backup drive.
 				backupRoots = append(backupRoots, store.HierarchyConfig.(hybridBackup.BackupTask).ParentUID)
-			} else if store.Hierarchy == "share" {
-				//Share emulated drive
-				var thisDevice = new(rootObject)
-				thisDevice.RootName = store.Name
-				thisDevice.RootPath = store.UUID + ":/"
-				thisDevice.rootID = store.UUID
-				roots = append(roots, thisDevice)
 			}
 		}
 
@@ -2349,97 +2323,68 @@ func system_fs_getFileProperties(w http.ResponseWriter, r *http.Request) {
 	vrootID, subpath, _ := filesystem.GetIDFromVirtualPath(vpath)
 	fsh, _ := GetFsHandlerByUUID(vrootID)
 	fshAbs := fsh.FileSystemAbstraction
-	if vrootID == "share" && subpath == "" {
-		result = fileProperties{
-			VirtualPath:    vpath,
-			StoragePath:    "(Emulated File System)",
-			Basename:       "Share",
-			VirtualDirname: filepath.ToSlash(filepath.Dir(vpath)),
-			StorageDirname: "N/A",
-			Ext:            "N/A",
-			MimeType:       "emulated/fs",
-			Filesize:       -1,
-			Permission:     "N/A",
-			LastModTime:    "N/A",
-			LastModUnix:    0,
-			IsDirectory:    true,
-			Owner:          "system",
-		}
-	} else {
-		rpath, err := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
-		if err != nil {
-			common.SendErrorResponse(w, err.Error())
-			return
-		}
-
-		fileStat, err := fshAbs.Stat(rpath)
-		if err != nil {
-			common.SendErrorResponse(w, err.Error())
-			return
-		}
 
-		fileMime := "text/directory"
-		if !fileStat.IsDir() {
-			m, _, err := fs.GetMime(rpath)
-			if err != nil {
-				fileMime = mime.TypeByExtension(filepath.Ext(rpath))
-			} else {
-				fileMime = m
-			}
+	rpath, err := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
+	if err != nil {
+		common.SendErrorResponse(w, err.Error())
+		return
+	}
 
-		}
+	fileStat, err := fshAbs.Stat(rpath)
+	if err != nil {
+		common.SendErrorResponse(w, err.Error())
+		return
+	}
 
-		filesize := fileStat.Size()
-		//Get file overall size if this is folder
-		if fileStat.IsDir() {
-			var size int64
-			fshAbs.Walk(rpath, func(_ string, info os.FileInfo, err error) error {
-				if err != nil {
-					return err
-				}
-				if !info.IsDir() {
-					size += info.Size()
-				}
-				return err
-			})
-			filesize = size
+	fileMime := "text/directory"
+	if !fileStat.IsDir() {
+		m, _, err := fs.GetMime(rpath)
+		if err != nil {
+			fileMime = mime.TypeByExtension(filepath.Ext(rpath))
+		} else {
+			fileMime = m
 		}
 
-		//Get file owner
-		owner := userinfo.GetFileOwner(rpath)
+	}
 
-		if owner == "" {
-			//Handle special virtual roots
-			vrootID, subpath, _ := filesystem.GetIDFromVirtualPath(vpath)
-			if vrootID == "share" {
-				//Share objects
-				shareOption, _ := shareEntryTable.ResolveShareOptionFromShareSubpath(subpath)
-				if shareOption != nil {
-					owner = shareOption.Owner
-				} else {
-					owner = "Unknown"
-				}
-			} else {
-				owner = "Unknown"
+	filesize := fileStat.Size()
+	//Get file overall size if this is folder
+	if fileStat.IsDir() {
+		var size int64
+		fshAbs.Walk(rpath, func(_ string, info os.FileInfo, err error) error {
+			if err != nil {
+				return err
+			}
+			if !info.IsDir() {
+				size += info.Size()
 			}
+			return err
+		})
+		filesize = size
+	}
 
-		}
+	//Get file owner
+	owner := userinfo.GetFileOwner(rpath)
 
-		result = fileProperties{
-			VirtualPath:    vpath,
-			StoragePath:    filepath.ToSlash(filepath.Clean(rpath)),
-			Basename:       filepath.Base(rpath),
-			VirtualDirname: filepath.ToSlash(filepath.Dir(vpath)),
-			StorageDirname: filepath.ToSlash(filepath.Dir(rpath)),
-			Ext:            filepath.Ext(rpath),
-			MimeType:       fileMime,
-			Filesize:       filesize,
-			Permission:     fileStat.Mode().Perm().String(),
-			LastModTime:    fileStat.ModTime().Format("2006-01-02 15:04:05"),
-			LastModUnix:    fileStat.ModTime().Unix(),
-			IsDirectory:    fileStat.IsDir(),
-			Owner:          owner,
-		}
+	if owner == "" {
+		//Handle special virtual roots
+		owner = "Unknown"
+	}
+
+	result = fileProperties{
+		VirtualPath:    vpath,
+		StoragePath:    filepath.ToSlash(filepath.Clean(rpath)),
+		Basename:       filepath.Base(rpath),
+		VirtualDirname: filepath.ToSlash(filepath.Dir(vpath)),
+		StorageDirname: filepath.ToSlash(filepath.Dir(rpath)),
+		Ext:            filepath.Ext(rpath),
+		MimeType:       fileMime,
+		Filesize:       filesize,
+		Permission:     fileStat.Mode().Perm().String(),
+		LastModTime:    fileStat.ModTime().Format("2006-01-02 15:04:05"),
+		LastModUnix:    fileStat.ModTime().Unix(),
+		IsDirectory:    fileStat.IsDir(),
+		Owner:          owner,
 	}
 
 	jsonString, _ := json.Marshal(result)
@@ -2489,87 +2434,81 @@ func system_fs_handleList(w http.ResponseWriter, r *http.Request) {
 	fshAbs := fsh.FileSystemAbstraction
 
 	var parsedFilelist []fs.FileData
-	//Handle some special virtual file systems / mount points
-	if fsh.UUID == "share" && subpath == "" {
-		userpgs := userinfo.GetUserPermissionGroupNames()
-		files := shareManager.ListRootForUser(userinfo, userpgs)
-		parsedFilelist = files
-	} else {
-		//Normal file systems
-		realpath, err := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
-		if err != nil {
-			common.SendErrorResponse(w, err.Error())
+
+	//Normal file systems
+	realpath, err := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
+	if err != nil {
+		common.SendErrorResponse(w, err.Error())
+		return
+	}
+	if !fshAbs.FileExists(realpath) {
+		//Path not exists
+		userRoot, _ := fshAbs.VirtualPathToRealPath("", userinfo.Username)
+		if filepath.Clean(realpath) == filepath.Clean(userRoot) {
+			//Initiate user folder (Initiaed in user object)
+			userinfo.GetHomeDirectory()
+		} else if !strings.Contains(filepath.ToSlash(filepath.Clean(currentDir)), "/") {
+			//User root not created. Create the root folder
+			os.MkdirAll(filepath.Clean(realpath), 0775)
+		} else {
+			//Folder not exists
+			log.Println("[File Explorer] Requested path: ", realpath, " does not exists!")
+			common.SendErrorResponse(w, "Folder not exists")
 			return
 		}
-		if !fshAbs.FileExists(realpath) {
-			//Path not exists
-			userRoot, _ := fshAbs.VirtualPathToRealPath("", userinfo.Username)
-			if filepath.Clean(realpath) == filepath.Clean(userRoot) {
-				//Initiate user folder (Initiaed in user object)
-				userinfo.GetHomeDirectory()
-			} else if !strings.Contains(filepath.ToSlash(filepath.Clean(currentDir)), "/") {
-				//User root not created. Create the root folder
-				os.MkdirAll(filepath.Clean(realpath), 0775)
-			} else {
-				//Folder not exists
-				log.Println("[File Explorer] Requested path: ", realpath, " does not exists!")
-				common.SendErrorResponse(w, "Folder not exists")
-				return
-			}
 
-		}
+	}
 
-		if sortMode == "" {
-			sortMode = "default"
-		}
+	if sortMode == "" {
+		sortMode = "default"
+	}
 
-		//Check for really special exception in where the path contains [ or ] which cannot be handled via Golang Glob function
-		files, err := fshAbs.Glob(realpath + "/*")
-		if err != nil {
-			log.Println("[File System] Unable to list dir: " + err.Error())
-			return
+	//Check for really special exception in where the path contains [ or ] which cannot be handled via Golang Glob function
+	files, err := fshAbs.Glob(realpath + "/*")
+	if err != nil {
+		log.Println("[File System] Unable to list dir: " + err.Error())
+		return
+	}
+	var shortCutInfo *shortcut.ShortcutData = nil
+	for _, v := range files {
+		//Check if it is hidden file
+		isHidden, _ := hidden.IsHidden(v, false)
+		if showHidden != "true" && isHidden {
+			//Skipping hidden files
+			continue
 		}
-		var shortCutInfo *shortcut.ShortcutData = nil
-		for _, v := range files {
-			//Check if it is hidden file
-			isHidden, _ := hidden.IsHidden(v, false)
-			if showHidden != "true" && isHidden {
-				//Skipping hidden files
-				continue
-			}
 
-			//Check if this is an aodb file
-			if filepath.Base(v) == "aofs.db" || filepath.Base(v) == "aofs.db.lock" {
-				//Database file (reserved)
-				continue
-			}
-
-			//Check if it is shortcut file. If yes, render a shortcut data struct
-			if filepath.Ext(v) == ".shortcut" {
-				//This is a shortcut file
-				shorcutData, err := shortcut.ReadShortcut(v)
-				if err == nil {
-					shortCutInfo = shorcutData
-				}
-			}
+		//Check if this is an aodb file
+		if filepath.Base(v) == "aofs.db" || filepath.Base(v) == "aofs.db.lock" {
+			//Database file (reserved)
+			continue
+		}
 
-			rawsize := fshAbs.GetFileSize(v)
-			modtime, _ := fshAbs.GetModTime(v)
-			thisvPath, _ := fshAbs.RealPathToVirtualPath(v, userinfo.Username)
-			thisFile := fs.FileData{
-				Filename:    filepath.Base(v),
-				Filepath:    currentDir + filepath.Base(v),
-				Realpath:    v,
-				IsDir:       fsh.FileSystemAbstraction.IsDir(v),
-				Filesize:    rawsize,
-				Displaysize: fs.GetFileDisplaySize(rawsize, 2),
-				ModTime:     modtime,
-				IsShared:    shareManager.FileIsShared(userinfo, thisvPath),
-				Shortcut:    shortCutInfo,
+		//Check if it is shortcut file. If yes, render a shortcut data struct
+		if filepath.Ext(v) == ".shortcut" {
+			//This is a shortcut file
+			shorcutData, err := shortcut.ReadShortcut(v)
+			if err == nil {
+				shortCutInfo = shorcutData
 			}
+		}
 
-			parsedFilelist = append(parsedFilelist, thisFile)
+		rawsize := fshAbs.GetFileSize(v)
+		modtime, _ := fshAbs.GetModTime(v)
+		thisvPath, _ := fshAbs.RealPathToVirtualPath(v, userinfo.Username)
+		thisFile := fs.FileData{
+			Filename:    filepath.Base(v),
+			Filepath:    currentDir + filepath.Base(v),
+			Realpath:    v,
+			IsDir:       fsh.FileSystemAbstraction.IsDir(v),
+			Filesize:    rawsize,
+			Displaysize: fs.GetFileDisplaySize(rawsize, 2),
+			ModTime:     modtime,
+			IsShared:    shareManager.FileIsShared(userinfo, thisvPath),
+			Shortcut:    shortCutInfo,
 		}
+
+		parsedFilelist = append(parsedFilelist, thisFile)
 	}
 
 	//Sort the filelist
@@ -2617,13 +2556,9 @@ func system_fs_handleDirHash(w http.ResponseWriter, r *http.Request) {
 		common.SendErrorResponse(w, "Unable to resolve target directory")
 		return
 	}
-	if fsh.UUID == "share" && subpath == "" {
-		common.SendTextResponse(w, hex.EncodeToString([]byte("0")))
-		return
-	}
 	fshAbs := fsh.FileSystemAbstraction
 
-	rpath, err := fshAbs.VirtualPathToRealPath(currentDir, userinfo.Username)
+	rpath, err := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
 	if err != nil {
 		common.SendErrorResponse(w, "Invalid dir given")
 		return

+ 1 - 1
mod/agi/agi.file.go

@@ -284,7 +284,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
 			rootDirs := []string{}
 			fileHandlers := u.GetAllFileSystemHandler()
 			for _, fsh := range fileHandlers {
-				if fsh.Hierarchy == "backup" || fsh.UUID == "share" {
+				if fsh.Hierarchy == "backup" {
 
 				} else {
 					rootDirs = append(rootDirs, fsh.UUID+":/")

+ 0 - 134
mod/filesystem/abstractions/sharefs/sharefs.go

@@ -1,134 +0,0 @@
-package sharefs
-
-import (
-	"errors"
-	"io"
-	"os"
-	"path/filepath"
-	"strings"
-	"time"
-
-	"imuslab.com/arozos/mod/filesystem/fserror"
-)
-
-/*
-	filesystemAbstraction.go
-
-	This file contains all the abstraction funtion of a local file system.
-
-*/
-
-type ShareFileSystemAbstraction struct {
-	UUID                     string
-	ShareUUIDToVpathResolver func(string) (string, error)
-}
-
-func NewShareFileSystemAbstraction(uuid string, resolverFunction func(string) (string, error)) ShareFileSystemAbstraction {
-	return ShareFileSystemAbstraction{
-		UUID:                     uuid,
-		ShareUUIDToVpathResolver: resolverFunction,
-	}
-}
-
-func (l ShareFileSystemAbstraction) Chmod(filename string, mode os.FileMode) error {
-	return nil
-}
-func (l ShareFileSystemAbstraction) Chown(filename string, uid int, gid int) error {
-	return nil
-}
-func (l ShareFileSystemAbstraction) Chtimes(filename string, atime time.Time, mtime time.Time) error {
-	return nil
-}
-func (l ShareFileSystemAbstraction) Create(filename string) (*os.File, error) {
-	return nil, nil
-}
-func (l ShareFileSystemAbstraction) Mkdir(filename string, mode os.FileMode) error {
-	return nil
-}
-func (l ShareFileSystemAbstraction) MkdirAll(filename string, mode os.FileMode) error {
-	return nil
-}
-func (l ShareFileSystemAbstraction) Name() string {
-	return ""
-}
-func (l ShareFileSystemAbstraction) Open(filename string) (*os.File, error) {
-	return nil, nil
-}
-func (l ShareFileSystemAbstraction) OpenFile(filename string, flag int, perm os.FileMode) (*os.File, error) {
-	return nil, nil
-}
-func (l ShareFileSystemAbstraction) Remove(filename string) error {
-	return nil
-}
-func (l ShareFileSystemAbstraction) RemoveAll(path string) error {
-	return nil
-}
-func (l ShareFileSystemAbstraction) Rename(oldname, newname string) error {
-	return nil
-}
-func (l ShareFileSystemAbstraction) Stat(filename string) (os.FileInfo, error) {
-	return nil, nil
-}
-
-/*
-	Abstraction Utilities
-*/
-
-func (l ShareFileSystemAbstraction) VirtualPathToRealPath(subpath string, username string) (string, error) {
-	subpath = filepath.ToSlash(filepath.Clean(subpath))
-	if strings.HasPrefix(subpath, l.UUID+":") {
-		subpath = strings.TrimPrefix(subpath, l.UUID+":")
-	}
-	subpath = subpath[1:] //Trim off the first / from the subpath
-	uuid := subpath
-	if strings.Contains(subpath, "/") {
-		uuid = strings.Split(subpath, "/")[0]
-	}
-
-	redirectVpath, err := l.ShareUUIDToVpathResolver(uuid)
-	if err != nil {
-		return "", err
-	}
-	return "", fserror.NewRedirectionError(redirectVpath)
-}
-
-func (l ShareFileSystemAbstraction) RealPathToVirtualPath(fullpath string, username string) (string, error) {
-	return "", errors.New("SHAREFS WORK IN PROGRESS")
-}
-
-func (l ShareFileSystemAbstraction) FileExists(realpath string) bool {
-	return false
-}
-
-func (l ShareFileSystemAbstraction) IsDir(realpath string) bool {
-	return false
-}
-
-func (l ShareFileSystemAbstraction) Glob(realpathWildcard string) ([]string, error) {
-	return []string{}, nil
-}
-
-func (l ShareFileSystemAbstraction) GetFileSize(realpath string) int64 {
-	return 0
-}
-
-func (l ShareFileSystemAbstraction) GetModTime(realpath string) (int64, error) {
-	return 0, fserror.ErrNullOperation
-}
-
-func (l ShareFileSystemAbstraction) WriteFile(filename string, content []byte, mode os.FileMode) error {
-	return nil
-}
-func (l ShareFileSystemAbstraction) ReadFile(filename string) ([]byte, error) {
-	return []byte(""), fserror.ErrNullOperation
-}
-func (l ShareFileSystemAbstraction) WriteStream(filename string, stream io.Reader, mode os.FileMode) error {
-	return fserror.ErrOperationNotSupported
-}
-func (l ShareFileSystemAbstraction) ReadStream(filename string) (io.ReadCloser, error) {
-	return nil, fserror.ErrOperationNotSupported
-}
-
-func (l ShareFileSystemAbstraction) Walk(root string, walkFn filepath.WalkFunc) error {
-	return fserror.ErrOperationNotSupported
-}

+ 1 - 24
mod/filesystem/filesystem.go

@@ -22,7 +22,6 @@ import (
 	db "imuslab.com/arozos/mod/database"
 	"imuslab.com/arozos/mod/disk/hybridBackup"
 	"imuslab.com/arozos/mod/filesystem/abstractions/localfs"
-	"imuslab.com/arozos/mod/filesystem/abstractions/sharefs"
 	"imuslab.com/arozos/mod/filesystem/abstractions/webdavfs"
 )
 
@@ -223,29 +222,7 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
 			Filesystem:            fstype,
 			Closed:                false,
 		}, nil
-	} else if option.Filesystem == "share" {
-		shareFsAbstraction := sharefs.NewShareFileSystemAbstraction(
-			"share",
-			func(s string) (string, error) {
-				log.Println(s)
-				return "user:/", nil
-			},
-		)
-		return &FileSystemHandler{
-			Name:                  option.Name,
-			UUID:                  option.Uuid,
-			Path:                  "",
-			ReadOnly:              option.Access == "readonly",
-			RequireBuffer:         false,
-			Parentuid:             option.Parentuid,
-			Hierarchy:             option.Hierarchy,
-			HierarchyConfig:       nil,
-			InitiationTime:        time.Now().Unix(),
-			FilesystemDatabase:    nil,
-			FileSystemAbstraction: shareFsAbstraction,
-			Filesystem:            fstype,
-			Closed:                false,
-		}, nil
+
 	} else if option.Filesystem == "virtual" {
 		//Virtual filesystem, deprecated
 		log.Println("Deprecated file system type: Virtual")

+ 6 - 0
mod/filesystem/fserror/fserror.go

@@ -9,9 +9,15 @@ package fserror
 import "errors"
 
 var (
+	//Redirective Error
+	ErrRedirectParent      = errors.New("Redirect:parent")
+	ErrRedirectCurrentRoot = errors.New("Redirect:root")
+	ErrRedirectUserRoot    = errors.New("Redirect:userroot")
+
 	//Resolve errors
 	ErrVpathResolveFailed = errors.New("FS_VPATH_RESOLVE_FAILED")
 	ErrRpathResolveFailed = errors.New("FS_RPATH_RESOLVE_FAILED")
+	ErrFSHNotFOund        = errors.New("FS_FILESYSTEM_HANDLER_NOT_FOUND")
 
 	//Operation errors
 	ErrOperationNotSupported = errors.New("FS_OPR_NOT_SUPPORTED")

+ 47 - 114
mod/share/share.go

@@ -853,26 +853,6 @@ func (s *Manager) HandleCreateNewShare(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	//Check if this is in the share folder
-	vrootID, subpath, err := filesystem.GetIDFromVirtualPath(vpath)
-	if err != nil {
-		sendErrorResponse(w, "Unable to resolve virtual path")
-		return
-	}
-	if vrootID == "share" {
-		shareObject, err := s.options.ShareEntryTable.ResolveShareOptionFromShareSubpath(subpath)
-		if err != nil {
-			sendErrorResponse(w, err.Error())
-			return
-		}
-
-		//Check if this share is own by or accessible by the current user. Reject share modification if not
-		if !shareObject.IsOwnedBy(userinfo.Username) && !userinfo.CanWrite(vpath) {
-			sendErrorResponse(w, "Permission Denied: You are not the file owner nor can write to this file")
-			return
-		}
-	}
-
 	//Get the target fsh that this vpath come from
 	vpathSourceFsh := userinfo.GetRootFSHFromVpathInUserScope(vpath)
 	if vpathSourceFsh == nil {
@@ -994,6 +974,45 @@ func (s *Manager) HandleDeleteShare(w http.ResponseWriter, r *http.Request) {
 	}
 }
 
+func (s *Manager) HandleListAllShares(w http.ResponseWriter, r *http.Request) {
+	userinfo, err := s.options.UserHandler.GetUserInfoFromRequest(w, r)
+	if err != nil {
+		common.SendErrorResponse(w, "User not logged in")
+		return
+	}
+	fshId, _ := common.Mv(r, "fsh", false)
+	results := []*shareEntry.ShareOption{}
+	if fshId == "" {
+		//List all
+		allFsh := userinfo.GetAllFileSystemHandler()
+		for _, thisFsh := range allFsh {
+			allShares := s.ListAllShareByFshId(thisFsh.UUID, userinfo)
+			for _, thisShare := range allShares {
+				if s.ShareIsValid(thisShare) {
+					results = append(results, thisShare)
+				}
+			}
+
+		}
+	} else {
+		//List fsh onlya
+		targetFsh, err := userinfo.GetFileSystemHandlerFromVirtualPath(fshId)
+		if err != nil {
+			common.SendErrorResponse(w, err.Error())
+			return
+		}
+		sharesInThisFsh := s.ListAllShareByFshId(targetFsh.UUID, userinfo)
+		for _, thisShare := range sharesInThisFsh {
+			if s.ShareIsValid(thisShare) {
+				results = append(results, thisShare)
+			}
+		}
+	}
+
+	js, _ := json.Marshal(results)
+	common.SendJSONResponse(w, string(js))
+}
+
 //Craete a new file or folder share
 func (s *Manager) CreateNewShare(userinfo *user.User, srcFsh *filesystem.FileSystemHandler, vpath string) (*shareEntry.ShareOption, error) {
 	//Translate the vpath to realpath
@@ -1052,106 +1071,20 @@ func validateShareModes(mode string) (bool, string, []string) {
 	return false, "", []string{}
 }
 
-func (s *Manager) Walk(subpath string, userinfo *user.User, fastWalkFunction func(filesystem.FileData) error) error {
-	//Resolve the subpath
-	usergroup := userinfo.GetUserPermissionGroupNames()
-	if subpath == "" {
-		//List root as a collections of shares
-		rootFileList := s.ListRootForUser(userinfo, usergroup)
-		for _, fileInRoot := range rootFileList {
-			fsh, err := userinfo.GetFileSystemHandlerFromVirtualPath(fileInRoot.Filepath)
-			if err != nil {
-				return err
-			}
-			runtimeRealpath, _ := fsh.FileSystemAbstraction.VirtualPathToRealPath(fileInRoot.Filepath, userinfo.Username)
-			if fsh.FileSystemAbstraction.IsDir(runtimeRealpath) {
-				//Walk it
-				err := fsh.FileSystemAbstraction.Walk(runtimeRealpath, func(path string, info os.FileInfo, err error) error {
-					relPath, err := filepath.Rel(runtimeRealpath, path)
-					if err != nil {
-						return err
-					}
-
-					thisVpath := filepath.ToSlash(filepath.Join(fileInRoot.Filepath, relPath))
-					thisFd := filesystem.GetFileDataFromPath(fsh, thisVpath, path, 2)
-					err = fastWalkFunction(thisFd)
-					if err != nil {
-						return err
-					}
-
-					return nil
-				})
-
-				return err
-			} else {
-				//Normal files
-				err := fastWalkFunction(fileInRoot)
-				if err != nil {
-					return err
-				}
+func (s *Manager) ListAllShareByFshId(fshId string, userinfo *user.User) []*shareEntry.ShareOption {
+	results := []*shareEntry.ShareOption{}
+	s.options.ShareEntryTable.FileToUrlMap.Range(func(k, v interface{}) bool {
+		thisShareOption := v.(*shareEntry.ShareOption)
+		if (!userinfo.IsAdmin() && thisShareOption.IsAccessibleBy(userinfo.Username, userinfo.GetUserPermissionGroupNames())) || userinfo.IsAdmin() {
+			id, _, _ := filesystem.GetIDFromVirtualPath(thisShareOption.FileVirtualPath)
+			if id == fshId {
+				results = append(results, thisShareOption)
 			}
 
 		}
-	} else {
-		//List realpath of the system
-
-		fmt.Println("RESOLVE", subpath)
-		/*
-			rpath, err := s.ResolveShareVrootPath(subpath, username, usergroup)
-			if err != nil {
-				return err
-			}
-
-			vpath := "share:/" + subpath
-			err = filepath.Walk(rpath, func(path string, info os.FileInfo, err error) error {
-
-				relPath, err := filepath.Rel(rpath, path)
-				if err != nil {
-					return err
-				}
-				thisVpath := filepath.ToSlash(filepath.Join(vpath, relPath))
-				thisFd := fs.GetFileDataFromPath(thisVpath, rpath, 2)
-				err = fastWalkFunction(thisFd)
-				if err != nil {
-					return err
-				}
-
-				return nil
-			})
-
-
-			return err
-		*/
-	}
-
-	return nil
-}
-
-func (s *Manager) ListRootForUser(userinfo *user.User, usergroup []string) []filesystem.FileData {
-	//Iterate through all shares in the system to see which of the share is user accessible
-	userAccessiableShare := []*shareEntry.ShareOption{}
-	s.options.ShareEntryTable.FileToUrlMap.Range(func(fp, so interface{}) bool {
-		thisShareOption := so.(*shareEntry.ShareOption)
-		if s.ShareIsValid(thisShareOption) && thisShareOption.IsAccessibleBy(userinfo.Username, usergroup) {
-			userAccessiableShare = append(userAccessiableShare, thisShareOption)
-		}
 		return true
 	})
 
-	results := []filesystem.FileData{}
-	for _, thisShareObject := range userAccessiableShare {
-		fsh, err := userinfo.GetFileSystemHandlerFromVirtualPath(thisShareObject.FileVirtualPath)
-		if err != nil {
-			continue
-		}
-		thisFile := filesystem.GetFileDataFromPath(fsh, "share:/"+thisShareObject.UUID+"/"+filepath.Base(thisShareObject.FileVirtualPath), thisShareObject.FileRealPath, 2)
-		if thisShareObject.Owner == userinfo.Username {
-			thisFile.IsShared = true
-		}
-
-		results = append(results, thisFile)
-	}
-
 	return results
 }
 

+ 0 - 34
mod/share/shareEntry/shareEntry.go

@@ -227,40 +227,6 @@ func (s *ShareEntryTable) ResolveShareOptionFromShareSubpath(subpath string) (*S
 	}
 }
 
-/*
-func (s *ShareEntryTable) ResolveShareVrootPath(subpath string, username string, usergroup []string) (string, error) {
-	//Get a list of accessible files from this user
-	subpathElements := strings.Split(filepath.ToSlash(filepath.Clean(subpath))[1:], "/")
-
-	if len(subpathElements) == 0 {
-		//Requesting root folder.
-		return "", errors.New("This virtual file system router do not support root listing")
-	}
-
-	//Analysis the subpath elements
-	if len(subpathElements) == 1 {
-		return "", errors.New("Redirect: parent")
-	} else if len(subpathElements) == 2 {
-		//ID only or ID with the target filename
-		shareObject := s.GetShareObjectFromUUID(subpathElements[0])
-		if shareObject == nil {
-			return "", errors.New("Share file not found")
-		}
-
-		return shareObject.FileRealPath, nil
-	} else if len(subpathElements) > 2 {
-		//Loading folder / files inside folder type shares
-		shareObject := s.GetShareObjectFromUUID(subpathElements[0])
-		folderSubpaths := append([]string{shareObject.FileRealPath}, subpathElements[2:]...)
-		targetFolder := filepath.Join(folderSubpaths...)
-		return targetFolder, nil
-	}
-
-	return "", errors.New("Not implemented")
-}
-
-*/
-
 func GetPathHash(fsh *filesystem.FileSystemHandler, vpath string, username string) string {
 	fshAbs := fsh.FileSystemAbstraction
 	rpath := ""

+ 2 - 2
mod/storage/storage.go

@@ -9,7 +9,6 @@ package storage
 */
 
 import (
-	"errors"
 	"log"
 	"os"
 	"strings"
@@ -17,6 +16,7 @@ import (
 	"imuslab.com/arozos/mod/disk/hybridBackup"
 	"imuslab.com/arozos/mod/filesystem"
 	fs "imuslab.com/arozos/mod/filesystem"
+	"imuslab.com/arozos/mod/filesystem/fserror"
 )
 
 type StoragePool struct {
@@ -128,7 +128,7 @@ func (s *StoragePool) GetFsHandlerByUUID(uuid string) (*fs.FileSystemHandler, er
 		}
 	}
 
-	return nil, errors.New("Filesystem handler with given UUID not found")
+	return nil, fserror.ErrFSHNotFOund
 }
 
 //Close all fsHandler under this storage pool

+ 0 - 2
mod/user/directoryHandler.go

@@ -128,8 +128,6 @@ func (u *User) VirtualPathToRealPath(vpath string) (string, error) {
 				return filepath.ToSlash(filepath.Join(filepath.Clean(storage.Path), "/users/", u.Username, subpath)), nil
 			} else if storage.Hierarchy == "public" {
 				return filepath.ToSlash(filepath.Join(filepath.Clean(storage.Path), subpath)), nil
-			} else if storage.Hierarchy == "share" {
-				//return (*u.parent.shareEntryTable).ResolveShareVrootPath(subpath, u.Username, u.GetUserPermissionGroupNames())
 			} else {
 				return "", errors.New("Unknown Filesystem Handler Hierarchy")
 			}

+ 35 - 32
storage.go

@@ -63,23 +63,24 @@ func LoadBaseStoragePool() error {
 	}
 	fsHandlers = append(fsHandlers, baseHandler)
 
-	//Load the special share folder as storage unit
-	shareHandler, err := fs.NewFileSystemHandler(fs.FileSystemOption{
-		Name:       "Share",
-		Uuid:       "share",
-		Path:       filepath.ToSlash(filepath.Clean(*tmp_directory)) + "/",
-		Access:     "readonly",
-		Hierarchy:  "share",
-		Automount:  false,
-		Filesystem: "share",
-	})
-
-	if err != nil {
-		log.Println("Failed to initiate share virtual storage directory: " + err.Error())
-		return err
-	}
-	fsHandlers = append(fsHandlers, shareHandler)
+	/*
+		//Load the special share folder as storage unit
+		shareHandler, err := fs.NewFileSystemHandler(fs.FileSystemOption{
+			Name:       "Share",
+			Uuid:       "share",
+			Path:       filepath.ToSlash(filepath.Clean(*tmp_directory)) + "/",
+			Access:     "readonly",
+			Hierarchy:  "share",
+			Automount:  false,
+			Filesystem: "share",
+		})
 
+		if err != nil {
+			log.Println("Failed to initiate share virtual storage directory: " + err.Error())
+			return err
+		}
+		fsHandlers = append(fsHandlers, shareHandler)
+	*/
 	//Load the tmp folder as storage unit
 	tmpHandler, err := fs.NewFileSystemHandler(fs.FileSystemOption{
 		Name:       "tmp",
@@ -101,22 +102,24 @@ func LoadBaseStoragePool() error {
 		DEBUG REMOVE AFTERWARD
 
 	*/
-	webdh, err := fs.NewFileSystemHandler(fs.FileSystemOption{
-		Name:       "Loopback",
-		Uuid:       "loopback",
-		Path:       "http://192.168.1.214:8081/webdav/user",
-		Access:     "readwrite",
-		Hierarchy:  "public",
-		Automount:  false,
-		Filesystem: "webdav",
-		Username:   "TC",
-		Password:   "password",
-	})
-	if err != nil {
-		log.Println(err.Error())
-	} else {
-		fsHandlers = append(fsHandlers, webdh)
-	}
+	/*
+		webdh, err := fs.NewFileSystemHandler(fs.FileSystemOption{
+			Name:       "Loopback",
+			Uuid:       "loopback",
+			Path:       "http://192.168.1.214:8081/webdav/user",
+			Access:     "readwrite",
+			Hierarchy:  "public",
+			Automount:  false,
+			Filesystem: "webdav",
+			Username:   "TC",
+			Password:   "password",
+		})
+		if err != nil {
+			log.Println(err.Error())
+		} else {
+			fsHandlers = append(fsHandlers, webdh)
+		}
+	*/
 
 	//Load all the storage config from file
 	rawConfig, err := ioutil.ReadFile(*storage_config_file)