|
@@ -5,6 +5,7 @@ import (
|
|
|
"encoding/hex"
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
+ "fmt"
|
|
|
"io"
|
|
|
"io/ioutil"
|
|
|
"log"
|
|
@@ -239,16 +240,37 @@ func system_fs_handleFileSearch(w http.ResponseWriter, r *http.Request) {
|
|
|
//Check if case sensitive is enabled
|
|
|
casesensitve, _ := mv(r, "casesensitive", true)
|
|
|
|
|
|
- //Translate the vpath to realpath
|
|
|
- rpath, err := userinfo.VirtualPathToRealPath(vpath)
|
|
|
+ vrootID, subpath, err := fs.GetIDFromVirtualPath(vpath)
|
|
|
+ var targetFSH *filesystem.FileSystemHandler = nil
|
|
|
if err != nil {
|
|
|
+
|
|
|
sendErrorResponse(w, "Invalid path given")
|
|
|
return
|
|
|
+ } else {
|
|
|
+ targetFSH, _ = GetFsHandlerByUUID(vrootID)
|
|
|
+ }
|
|
|
+ rpath := ""
|
|
|
+ if targetFSH != nil && targetFSH.Filesystem != "virtual" {
|
|
|
+ //Translate the vpath to realpath if this is an actual path on disk
|
|
|
+ resolvedPath, err := userinfo.VirtualPathToRealPath(vpath)
|
|
|
+ if err != nil {
|
|
|
+ sendErrorResponse(w, "Invalid path given")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ rpath = resolvedPath
|
|
|
}
|
|
|
|
|
|
//Check if the search mode is recursive keyword or wildcard
|
|
|
if len(keyword) > 1 && keyword[:1] == "/" {
|
|
|
//Wildcard
|
|
|
+
|
|
|
+ //Updates 31-12-2021: Do not allow wildcard search on virtual type's FSH
|
|
|
+ if targetFSH != nil && targetFSH.Filesystem == "virtual" {
|
|
|
+ sendErrorResponse(w, "This virtual storage device do not allow wildcard search")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
wildcard := keyword[1:]
|
|
|
matchingFiles, err := filepath.Glob(filepath.Join(rpath, wildcard))
|
|
|
if err != nil {
|
|
@@ -287,25 +309,40 @@ func system_fs_handleFileSearch(w http.ResponseWriter, r *http.Request) {
|
|
|
//Recursive keyword
|
|
|
results := []fs.FileData{}
|
|
|
var err error = nil
|
|
|
- if casesensitve == "true" {
|
|
|
- //Require case sensitive match
|
|
|
- err = filepath.Walk(rpath, func(path string, info os.FileInfo, err error) error {
|
|
|
- if strings.Contains(filepath.Base(path), keyword) {
|
|
|
- //This is a matching file
|
|
|
- if !fs.IsInsideHiddenFolder(path) {
|
|
|
- thisVpath, _ := userinfo.RealPathToVirtualPath(path)
|
|
|
- results = append(results, fs.GetFileDataFromPath(thisVpath, path, 2))
|
|
|
- }
|
|
|
-
|
|
|
+ if targetFSH != nil && targetFSH.Filesystem == "virtual" {
|
|
|
+ //To be done: Move hardcoded vroot ID to interface for all virtual storage devices
|
|
|
+ if vrootID == "share" {
|
|
|
+ if casesensitve != "true" {
|
|
|
+ keyword = strings.ToLower(keyword)
|
|
|
}
|
|
|
- return nil
|
|
|
- })
|
|
|
+ err = shareEntryTable.Walk(subpath, userinfo.Username, userinfo.GetUserPermissionGroupNames(), func(fileData fs.FileData) error {
|
|
|
+ filename := filepath.Base(fileData.Filename)
|
|
|
+ if casesensitve != "true" {
|
|
|
+ filename = strings.ToLower(filename)
|
|
|
+ }
|
|
|
+ if strings.Contains(filename, keyword) {
|
|
|
+ //This is a matching file
|
|
|
+ if !fs.IsInsideHiddenFolder(fileData.Filepath) {
|
|
|
+ results = append(results, fileData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ log.Println("Dynamic virtual root walk is not supported yet: ", vrootID)
|
|
|
+ }
|
|
|
} else {
|
|
|
- //Require general match
|
|
|
- keywordLower := strings.ToLower(keyword)
|
|
|
- err = filepath.Walk(rpath, func(path string, info os.FileInfo, err error) error {
|
|
|
+ if casesensitve != "true" {
|
|
|
+ keyword = strings.ToLower(keyword)
|
|
|
+ }
|
|
|
|
|
|
- if strings.Contains(strings.ToLower(filepath.Base(path)), keywordLower) {
|
|
|
+ fmt.Println(rpath)
|
|
|
+ err = filepath.Walk(rpath, func(path string, info os.FileInfo, err error) error {
|
|
|
+ thisFilename := filepath.Base(path)
|
|
|
+ if casesensitve != "true" {
|
|
|
+ thisFilename = strings.ToLower(thisFilename)
|
|
|
+ }
|
|
|
+ if strings.Contains(thisFilename, keyword) {
|
|
|
//This is a matching file
|
|
|
if !fs.IsInsideHiddenFolder(path) {
|
|
|
thisVpath, _ := userinfo.RealPathToVirtualPath(path)
|
|
@@ -321,7 +358,6 @@ func system_fs_handleFileSearch(w http.ResponseWriter, r *http.Request) {
|
|
|
sendErrorResponse(w, err.Error())
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
//OK. Tidy up the results
|
|
|
js, _ := json.Marshal(results)
|
|
|
sendJSONResponse(w, string(js))
|
|
@@ -1082,14 +1118,14 @@ func system_fs_handleNewObjects(w http.ResponseWriter, r *http.Request) {
|
|
|
//Translate the path to realpath
|
|
|
rpath, err := userinfo.VirtualPathToRealPath(vsrc)
|
|
|
if err != nil {
|
|
|
- sendErrorResponse(w, "Invalid path given.")
|
|
|
+ sendErrorResponse(w, "Invalid path given")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//Check if directory is readonly
|
|
|
accmode := userinfo.GetPathAccessPermission(vsrc)
|
|
|
if accmode == "readonly" {
|
|
|
- sendErrorResponse(w, "This directory is Read Only.")
|
|
|
+ sendErrorResponse(w, "This directory is Read Only")
|
|
|
return
|
|
|
} else if accmode == "denied" {
|
|
|
sendErrorResponse(w, "Access Denied")
|
|
@@ -1100,7 +1136,7 @@ func system_fs_handleNewObjects(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
if fileType == "file" {
|
|
|
for fileExists(newfilePath) {
|
|
|
- sendErrorResponse(w, "Given filename already exists.")
|
|
|
+ sendErrorResponse(w, "Given filename already exists")
|
|
|
return
|
|
|
}
|
|
|
ext := filepath.Ext(filename)
|
|
@@ -1139,7 +1175,7 @@ func system_fs_handleNewObjects(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
} else if fileType == "folder" {
|
|
|
if fileExists(newfilePath) {
|
|
|
- sendErrorResponse(w, "Given folder already exists.")
|
|
|
+ sendErrorResponse(w, "Given folder already exists")
|
|
|
return
|
|
|
}
|
|
|
//Create the folder at target location
|
|
@@ -1519,7 +1555,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
|
|
|
if fileExists(edgeCaseFilename) {
|
|
|
rsrcFile = edgeCaseFilename
|
|
|
} else {
|
|
|
- sendErrorResponse(w, "Source file not exists.")
|
|
|
+ sendErrorResponse(w, "Source file not exists")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1545,7 +1581,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
|
|
|
//Check if the target dir is not readonly
|
|
|
accmode := userinfo.GetPathAccessPermission(string(vsrcFile))
|
|
|
if accmode == "readonly" {
|
|
|
- sendErrorResponse(w, "This directory is Read Only.")
|
|
|
+ sendErrorResponse(w, "This directory is Read Only")
|
|
|
return
|
|
|
} else if accmode == "denied" {
|
|
|
sendErrorResponse(w, "Access Denied")
|
|
@@ -1596,7 +1632,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
|
|
|
//Check if the source file is read only.
|
|
|
accmode := userinfo.GetPathAccessPermission(string(vsrcFile))
|
|
|
if accmode == "readonly" {
|
|
|
- sendErrorResponse(w, "This source file is Read Only.")
|
|
|
+ sendErrorResponse(w, "This source file is Read Only")
|
|
|
return
|
|
|
} else if accmode == "denied" {
|
|
|
sendErrorResponse(w, "Access Denied")
|
|
@@ -1604,7 +1640,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
if rdestFile == "" {
|
|
|
- sendErrorResponse(w, "Undefined dest location.")
|
|
|
+ sendErrorResponse(w, "Undefined dest location")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1657,14 +1693,14 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
//Check if the desintation is read only.
|
|
|
if !userinfo.CanWrite(vdestFile) {
|
|
|
- sendErrorResponse(w, "Access Denied.")
|
|
|
+ sendErrorResponse(w, "Access Denied")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if !fileExists(rdestFile) {
|
|
|
if fileExists(filepath.Dir(rdestFile)) {
|
|
|
//User pass in the whole path for the folder. Report error usecase.
|
|
|
- sendErrorResponse(w, "Dest location should be an existing folder instead of the full path of the copied file.")
|
|
|
+ sendErrorResponse(w, "Dest location should be an existing folder instead of the full path of the copied file")
|
|
|
return
|
|
|
}
|
|
|
sendErrorResponse(w, "Dest folder not found")
|
|
@@ -1698,7 +1734,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
if !userinfo.CanWrite(vsrcFile) {
|
|
|
- sendErrorResponse(w, "Access Denied.")
|
|
|
+ sendErrorResponse(w, "Access Denied")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1741,7 +1777,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}*/
|
|
|
if !userinfo.CanWrite(vsrcFile) {
|
|
|
- sendErrorResponse(w, "Access Denied.")
|
|
|
+ sendErrorResponse(w, "Access Denied")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1764,7 +1800,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
//Check if the user can write to the target dest file
|
|
|
if userinfo.CanWrite(string(vdestFile)) == false {
|
|
|
- sendErrorResponse(w, "Access Denied.")
|
|
|
+ sendErrorResponse(w, "Access Denied")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1785,7 +1821,7 @@ func system_fs_handleOpr(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- sendErrorResponse(w, "Unknown file opeartion given.")
|
|
|
+ sendErrorResponse(w, "Unknown file opeartion given")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
@@ -2177,11 +2213,7 @@ func system_fs_handleList(w http.ResponseWriter, r *http.Request) {
|
|
|
//Handle some special virtual file systems / mount points
|
|
|
if VirtualRootID == "share" && subpath == "" {
|
|
|
userpgs := userinfo.GetUserPermissionGroupNames()
|
|
|
- files, err := shareEntryTable.RouteShareVroot(subpath, userinfo.Username, userpgs)
|
|
|
- if err != nil {
|
|
|
- sendErrorResponse(w, "Error. Unable to parse path. "+err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
+ files := shareEntryTable.ListRootForUser(userinfo.Username, userpgs)
|
|
|
parsedFilelist = files
|
|
|
} else {
|
|
|
//Normal file systems
|