CasaOS - A simple, easy-to-use, elegant open-source Personal Cloud system.
Mounted folders are inoperable
link8e025a98362f
diff --git a/go.mod b/go.modindex 7581fe8..9bf1cfc 100644--- a/go.mod+++ b/go.mod@@ -4,7 +4,7 @@ go 1.19require (github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d- github.com/IceWhaleTech/CasaOS-Common v0.4.2-alpha1+ github.com/IceWhaleTech/CasaOS-Common v0.4.2-alpha2github.com/Xhofe/go-cache v0.0.0-20220723083548-714439c8af9agithub.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcfgithub.com/deckarep/golang-set/v2 v2.1.0@@ -29,6 +29,7 @@ require (github.com/labstack/echo/v4 v4.10.0github.com/maruel/natural v1.1.0github.com/mholt/archiver/v3 v3.5.1+ github.com/moby/sys/mountinfo v0.6.2github.com/patrickmn/go-cache v2.1.0+incompatiblegithub.com/pkg/errors v0.9.1github.com/robfig/cron v1.2.0diff --git a/go.sum b/go.sumindex 372f869..fb7548b 100644--- a/go.sum+++ b/go.sum@@ -1,8 +1,8 @@github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d h1:62lEBImTxZ83pgzywgDNIrPPuQ+j4ep9QjqrWBn1hrU=github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d/go.mod h1:lW9x+yEjqKdPbE3+cf2fGPJXCw/hChX3Omi9QHTLFsQ=-github.com/IceWhaleTech/CasaOS-Common v0.4.2-alpha1 h1:4Z61swpEC/OUGLlzww1v/D916j7yqYnfBevdVD/dgjI=-github.com/IceWhaleTech/CasaOS-Common v0.4.2-alpha1/go.mod h1:xcemiRsXcs1zrmQxYMyExDjZ7UHYwkJqYE71IDIV0xA=+github.com/IceWhaleTech/CasaOS-Common v0.4.2-alpha2 h1:46wHhGnMqVtVrgMCKiR3TpJ3mOBCpoTIP54JGCILs1k=+github.com/IceWhaleTech/CasaOS-Common v0.4.2-alpha2/go.mod h1:xcemiRsXcs1zrmQxYMyExDjZ7UHYwkJqYE71IDIV0xA=github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=github.com/Xhofe/go-cache v0.0.0-20220723083548-714439c8af9a h1:RenIAa2q4H8UcS/cqmwdT1WCWIAH5aumP8m8RpbqVsE=github.com/Xhofe/go-cache v0.0.0-20220723083548-714439c8af9a/go.mod h1:sSBbaOg90XwWKtpT56kVujF0bIeVITnPlssLclogS04=@@ -201,6 +201,8 @@ github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjgithub.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=github.com/mholt/archiver/v3 v3.5.1 h1:rDjOBX9JSF5BvoJGvjqK479aL70qh9DIpZCl+k7Clwo=github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4=+github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78=+github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=@@ -337,6 +339,7 @@ golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBcgolang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=diff --git a/pkg/utils/common_err/e.go b/pkg/utils/common_err/e.goindex 605b9b8..92962b4 100644--- a/pkg/utils/common_err/e.go+++ b/pkg/utils/common_err/e.go@@ -46,11 +46,12 @@ const (ERROR_APP_NAME_EXIST = 50004//file- FILE_DOES_NOT_EXIST = 60001- FILE_READ_ERROR = 60002- FILE_DELETE_ERROR = 60003- DIR_NOT_EXISTS = 60004- SOURCE_DES_SAME = 60005+ FILE_DOES_NOT_EXIST = 60001+ FILE_READ_ERROR = 60002+ FILE_DELETE_ERROR = 60003+ DIR_NOT_EXISTS = 60004+ SOURCE_DES_SAME = 60005+ MOUNTED_DIRECTIORIES = 60006//shareSHARE_ALREADY_EXISTS = 70001@@ -109,8 +110,9 @@ var MsgFlags = map[int]string{DIR_NOT_EXISTS: "Directory does not exist",- FILE_READ_ERROR: "File read error",- FILE_DELETE_ERROR: "Delete error",+ FILE_READ_ERROR: "File read error",+ FILE_DELETE_ERROR: "Delete error",+ MOUNTED_DIRECTIORIES: "The directory is mounted, please unmount it first.",COMMAND_ERROR_INVALID_OPERATION: "invalid operation",}diff --git a/route/init.go b/route/init.goindex cb8f8c3..eee2426 100644--- a/route/init.go+++ b/route/init.go@@ -73,7 +73,11 @@ func InitNetworkMount() {}baseHostPath := "/mnt/" + connection.Host- mountPointList := service.MyService.System().GetDirPath(baseHostPath)+ mountPointList, err := service.MyService.System().GetDirPath(baseHostPath)+ if err != nil {+ logger.Error("get mount point err", zap.Any("err", err))+ continue+ }for _, v := range mountPointList {service.MyService.Connections().UnmountSmaba(v.Path)}diff --git a/route/v1/file.go b/route/v1/file.goindex efec489..ba62b73 100644--- a/route/v1/file.go+++ b/route/v1/file.go@@ -253,11 +253,15 @@ func GetDownloadSingleFile(c *gin.Context) {func DirPath(c *gin.Context) {var req ListReqif err := c.ShouldBind(&req); err != nil {- c.JSON(common_err.SUCCESS, model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.CLIENT_ERROR), Data: err.Error()})+ c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.CLIENT_ERROR), Data: err.Error()})return}req.Validate()- info := service.MyService.System().GetDirPath(req.Path)+ info, err := service.MyService.System().GetDirPath(req.Path)+ if err != nil {+ c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})+ return+ }shares := service.MyService.Shares().GetSharesList()sharesMap := make(map[string]string)for _, v := range shares {@@ -278,6 +282,18 @@ func DirPath(c *gin.Context) {shareEx["shared"] = "true"shareEx["id"] = vex["share"] = shareEx+ ex["mounted"] = false+ info[i].Extensions = ex+ }+ }+ if strings.HasPrefix(req.Path, "/mnt") || strings.HasPrefix(req.Path, "/media") {+ for i := (req.Index - 1) * req.Size; i < forEnd; i++ {+ ex := info[i].Extensions+ if ex == nil {+ ex = make(map[string]interface{})+ }+ mounted := service.IsMounted(info[i].Path)+ ex["mounted"] = mountedinfo[i].Extensions = ex}}@@ -344,6 +360,12 @@ func RenamePath(c *gin.Context) {c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})return}+ mounted := service.IsMounted(op)+ if mounted {+ c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.MOUNTED_DIRECTIORIES, Message: common_err.GetMsg(common_err.MOUNTED_DIRECTIORIES), Data: common_err.GetMsg(common_err.MOUNTED_DIRECTIORIES)})+ return+ }+success, err := service.MyService.System().RenameFile(op, np)c.JSON(common_err.SUCCESS, model.Result{Success: success, Message: common_err.GetMsg(success), Data: err})}@@ -570,6 +592,13 @@ func PostOperateFileOrDir(c *gin.Context) {}list.Item[i].Size = sizetotal += size+ if list.Type == "move" {+ mounted := service.IsMounted(list.Item[i].From)+ if mounted {+ c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.MOUNTED_DIRECTIORIES, Message: common_err.GetMsg(common_err.MOUNTED_DIRECTIORIES), Data: common_err.GetMsg(common_err.MOUNTED_DIRECTIORIES)})+ return+ }+ }}list.TotalSize = total@@ -607,6 +636,13 @@ func DeleteFile(c *gin.Context) {// path := c.Query("path")// paths := strings.Split(path, ",")+ for _, v := range paths {+ mounted := service.IsMounted(v)+ if mounted {+ c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.MOUNTED_DIRECTIORIES, Message: common_err.GetMsg(common_err.MOUNTED_DIRECTIORIES), Data: common_err.GetMsg(common_err.MOUNTED_DIRECTIORIES)})+ return+ }+ }for _, v := range paths {err := os.RemoveAll(v)diff --git a/route/v1/recover.go b/route/v1/recover.goindex 5d4de60..57793b6 100644--- a/route/v1/recover.go+++ b/route/v1/recover.go@@ -4,6 +4,7 @@ import ("strings""time"+ "github.com/IceWhaleTech/CasaOS-Common/utils/file""github.com/IceWhaleTech/CasaOS/drivers/dropbox""github.com/IceWhaleTech/CasaOS/drivers/google_drive""github.com/IceWhaleTech/CasaOS/service"@@ -54,7 +55,7 @@ func GetRecoverStorage(c *gin.Context) {a := strings.Split(username, "@")username = a[0]}- username += "_drive"+ username += file.NameAccumulation(username)dataMap, _ := service.MyService.Storage().GetConfigByName(username)if len(dataMap) > 0 {c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)@@ -111,7 +112,7 @@ func GetRecoverStorage(c *gin.Context) {a := strings.Split(username, "@")username = a[0]}- username += "_dropbox"+ username += file.NameAccumulation(username)dataMap, _ := service.MyService.Storage().GetConfigByName(username)if len(dataMap) > 0 {c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)diff --git a/route/v1/samba.go b/route/v1/samba.goindex 39e0b66..30cfb81 100644--- a/route/v1/samba.go+++ b/route/v1/samba.go@@ -197,7 +197,11 @@ func DeleteSambaConnections(c *gin.Context) {c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.Record_NOT_EXIST, Message: common_err.GetMsg(common_err.Record_NOT_EXIST)})return}- mountPointList := service.MyService.System().GetDirPath(connection.MountPoint)+ mountPointList, err := service.MyService.System().GetDirPath(connection.MountPoint)+ if err != nil {+ c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})+ return+ }for _, v := range mountPointList {service.MyService.Connections().UnmountSmaba(v.Path)}diff --git a/service/file.go b/service/file.goindex d68b662..049994a 100644--- a/service/file.go+++ b/service/file.go@@ -22,6 +22,7 @@ import ("github.com/IceWhaleTech/CasaOS-Common/utils/logger""github.com/IceWhaleTech/CasaOS/model""github.com/IceWhaleTech/CasaOS/pkg/utils/file"+ "github.com/moby/sys/mountinfo""go.uber.org/zap")@@ -172,3 +173,16 @@ func CheckFileStatus() {time.Sleep(time.Second * 3)}}+func IsMounted(path string) bool {+ mounted, _ := mountinfo.Mounted(path)+ if mounted {+ return true+ }+ connections := MyService.Connections().GetConnectionsList()+ for _, v := range connections {+ if v.MountPoint == path {+ return true+ }+ }+ return false+}diff --git a/service/shares.go b/service/shares.goindex 1f8b096..2c0a870 100644--- a/service/shares.go+++ b/service/shares.go@@ -82,6 +82,7 @@ read only = Noguest ok = Yescreate mask = 0777directory mask = 0777+guest account = root`}diff --git a/service/system.go b/service/system.goindex f66e93b..4c29c85 100644--- a/service/system.go+++ b/service/system.go@@ -19,6 +19,7 @@ import ("github.com/IceWhaleTech/CasaOS/pkg/config"command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command""github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"+ "go.uber.org/zap""github.com/shirou/gopsutil/v3/cpu""github.com/shirou/gopsutil/v3/disk"@@ -42,7 +43,7 @@ type SystemService interface {GetCpuPercent() float64GetMemInfo() map[string]interface{}GetCpuInfo() []cpu.InfoStat- GetDirPath(path string) []model.Path+ GetDirPath(path string) ([]model.Path, error)GetDirPathOne(path string) (m model.Path)GetNetState(name string) stringGetDiskInfo() *disk.UsageStat@@ -156,7 +157,7 @@ func (c *systemService) GetDirPathOne(path string) (m model.Path) {return}-func (c *systemService) GetDirPath(path string) []model.Path {+func (c *systemService) GetDirPath(path string) ([]model.Path, error) {if path == "/DATA" {sysType := runtime.GOOSif sysType == "windows" {@@ -168,7 +169,11 @@ func (c *systemService) GetDirPath(path string) []model.Path {}- ls, _ := ioutil.ReadDir(path)+ ls, err := ioutil.ReadDir(path)+ if err != nil {+ logger.Error("when read dir", zap.Error(err))+ return []model.Path{}, err+ }dirs := []model.Path{}if len(path) > 0 {for _, l := range ls {@@ -187,7 +192,7 @@ func (c *systemService) GetDirPath(path string) []model.Path {} else {dirs = append(dirs, model.Path{Name: "DATA", Path: "/DATA/", IsDir: true, Date: time.Now()})}- return dirs+ return dirs, nil}func (c *systemService) GetCpuInfo() []cpu.InfoStat {