Mounted folders are inoperable

This commit is contained in:
link 2023-02-07 06:38:21 +00:00
parent 8343f52137
commit 8e025a9836
10 changed files with 91 additions and 20 deletions

3
go.mod
View file

@ -4,7 +4,7 @@ go 1.19
require ( require (
github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d 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-alpha2
github.com/Xhofe/go-cache v0.0.0-20220723083548-714439c8af9a github.com/Xhofe/go-cache v0.0.0-20220723083548-714439c8af9a
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
github.com/deckarep/golang-set/v2 v2.1.0 github.com/deckarep/golang-set/v2 v2.1.0
@ -29,6 +29,7 @@ require (
github.com/labstack/echo/v4 v4.10.0 github.com/labstack/echo/v4 v4.10.0
github.com/maruel/natural v1.1.0 github.com/maruel/natural v1.1.0
github.com/mholt/archiver/v3 v3.5.1 github.com/mholt/archiver/v3 v3.5.1
github.com/moby/sys/mountinfo v0.6.2
github.com/patrickmn/go-cache v2.1.0+incompatible github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/robfig/cron v1.2.0 github.com/robfig/cron v1.2.0

7
go.sum
View file

@ -1,8 +1,8 @@
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= 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 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/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-alpha2 h1:46wHhGnMqVtVrgMCKiR3TpJ3mOBCpoTIP54JGCILs1k=
github.com/IceWhaleTech/CasaOS-Common v0.4.2-alpha1/go.mod h1:xcemiRsXcs1zrmQxYMyExDjZ7UHYwkJqYE71IDIV0xA= 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/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 h1:RenIAa2q4H8UcS/cqmwdT1WCWIAH5aumP8m8RpbqVsE=
github.com/Xhofe/go-cache v0.0.0-20220723083548-714439c8af9a/go.mod h1:sSBbaOg90XwWKtpT56kVujF0bIeVITnPlssLclogS04= 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:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOj
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.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 h1:rDjOBX9JSF5BvoJGvjqK479aL70qh9DIpZCl+k7Clwo=
github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4= 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-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 h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 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:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.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-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-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-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-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

View file

@ -46,11 +46,12 @@ const (
ERROR_APP_NAME_EXIST = 50004 ERROR_APP_NAME_EXIST = 50004
//file //file
FILE_DOES_NOT_EXIST = 60001 FILE_DOES_NOT_EXIST = 60001
FILE_READ_ERROR = 60002 FILE_READ_ERROR = 60002
FILE_DELETE_ERROR = 60003 FILE_DELETE_ERROR = 60003
DIR_NOT_EXISTS = 60004 DIR_NOT_EXISTS = 60004
SOURCE_DES_SAME = 60005 SOURCE_DES_SAME = 60005
MOUNTED_DIRECTIORIES = 60006
//share //share
SHARE_ALREADY_EXISTS = 70001 SHARE_ALREADY_EXISTS = 70001
@ -109,8 +110,9 @@ var MsgFlags = map[int]string{
DIR_NOT_EXISTS: "Directory does not exist", DIR_NOT_EXISTS: "Directory does not exist",
FILE_READ_ERROR: "File read error", FILE_READ_ERROR: "File read error",
FILE_DELETE_ERROR: "Delete error", FILE_DELETE_ERROR: "Delete error",
MOUNTED_DIRECTIORIES: "The directory is mounted, please unmount it first.",
COMMAND_ERROR_INVALID_OPERATION: "invalid operation", COMMAND_ERROR_INVALID_OPERATION: "invalid operation",
} }

View file

@ -73,7 +73,11 @@ func InitNetworkMount() {
} }
baseHostPath := "/mnt/" + connection.Host 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 { for _, v := range mountPointList {
service.MyService.Connections().UnmountSmaba(v.Path) service.MyService.Connections().UnmountSmaba(v.Path)
} }

View file

@ -253,11 +253,15 @@ func GetDownloadSingleFile(c *gin.Context) {
func DirPath(c *gin.Context) { func DirPath(c *gin.Context) {
var req ListReq var req ListReq
if err := c.ShouldBind(&req); err != nil { if 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 return
} }
req.Validate() 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() shares := service.MyService.Shares().GetSharesList()
sharesMap := make(map[string]string) sharesMap := make(map[string]string)
for _, v := range shares { for _, v := range shares {
@ -278,6 +282,18 @@ func DirPath(c *gin.Context) {
shareEx["shared"] = "true" shareEx["shared"] = "true"
shareEx["id"] = v shareEx["id"] = v
ex["share"] = shareEx ex["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"] = mounted
info[i].Extensions = ex info[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)}) c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return 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) success, err := service.MyService.System().RenameFile(op, np)
c.JSON(common_err.SUCCESS, model.Result{Success: success, Message: common_err.GetMsg(success), Data: err}) 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 = size list.Item[i].Size = size
total += size total += 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 list.TotalSize = total
@ -607,6 +636,13 @@ func DeleteFile(c *gin.Context) {
// path := c.Query("path") // path := c.Query("path")
// paths := strings.Split(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 { for _, v := range paths {
err := os.RemoveAll(v) err := os.RemoveAll(v)

View file

@ -4,6 +4,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/IceWhaleTech/CasaOS-Common/utils/file"
"github.com/IceWhaleTech/CasaOS/drivers/dropbox" "github.com/IceWhaleTech/CasaOS/drivers/dropbox"
"github.com/IceWhaleTech/CasaOS/drivers/google_drive" "github.com/IceWhaleTech/CasaOS/drivers/google_drive"
"github.com/IceWhaleTech/CasaOS/service" "github.com/IceWhaleTech/CasaOS/service"
@ -54,7 +55,7 @@ func GetRecoverStorage(c *gin.Context) {
a := strings.Split(username, "@") a := strings.Split(username, "@")
username = a[0] username = a[0]
} }
username += "_drive" username += file.NameAccumulation(username)
dataMap, _ := service.MyService.Storage().GetConfigByName(username) dataMap, _ := service.MyService.Storage().GetConfigByName(username)
if len(dataMap) > 0 { if len(dataMap) > 0 {
c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`) 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, "@") a := strings.Split(username, "@")
username = a[0] username = a[0]
} }
username += "_dropbox" username += file.NameAccumulation(username)
dataMap, _ := service.MyService.Storage().GetConfigByName(username) dataMap, _ := service.MyService.Storage().GetConfigByName(username)
if len(dataMap) > 0 { if len(dataMap) > 0 {
c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`) c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)

View file

@ -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)}) c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.Record_NOT_EXIST, Message: common_err.GetMsg(common_err.Record_NOT_EXIST)})
return 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 { for _, v := range mountPointList {
service.MyService.Connections().UnmountSmaba(v.Path) service.MyService.Connections().UnmountSmaba(v.Path)
} }

View file

@ -22,6 +22,7 @@ import (
"github.com/IceWhaleTech/CasaOS-Common/utils/logger" "github.com/IceWhaleTech/CasaOS-Common/utils/logger"
"github.com/IceWhaleTech/CasaOS/model" "github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file" "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
"github.com/moby/sys/mountinfo"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -172,3 +173,16 @@ func CheckFileStatus() {
time.Sleep(time.Second * 3) 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
}

View file

@ -82,6 +82,7 @@ read only = No
guest ok = Yes guest ok = Yes
create mask = 0777 create mask = 0777
directory mask = 0777 directory mask = 0777
guest account = root
` `
} }

View file

@ -19,6 +19,7 @@ import (
"github.com/IceWhaleTech/CasaOS/pkg/config" "github.com/IceWhaleTech/CasaOS/pkg/config"
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command" command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err" "github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
"go.uber.org/zap"
"github.com/shirou/gopsutil/v3/cpu" "github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/disk" "github.com/shirou/gopsutil/v3/disk"
@ -42,7 +43,7 @@ type SystemService interface {
GetCpuPercent() float64 GetCpuPercent() float64
GetMemInfo() map[string]interface{} GetMemInfo() map[string]interface{}
GetCpuInfo() []cpu.InfoStat GetCpuInfo() []cpu.InfoStat
GetDirPath(path string) []model.Path GetDirPath(path string) ([]model.Path, error)
GetDirPathOne(path string) (m model.Path) GetDirPathOne(path string) (m model.Path)
GetNetState(name string) string GetNetState(name string) string
GetDiskInfo() *disk.UsageStat GetDiskInfo() *disk.UsageStat
@ -156,7 +157,7 @@ func (c *systemService) GetDirPathOne(path string) (m model.Path) {
return return
} }
func (c *systemService) GetDirPath(path string) []model.Path { func (c *systemService) GetDirPath(path string) ([]model.Path, error) {
if path == "/DATA" { if path == "/DATA" {
sysType := runtime.GOOS sysType := runtime.GOOS
if sysType == "windows" { if 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{} dirs := []model.Path{}
if len(path) > 0 { if len(path) > 0 {
for _, l := range ls { for _, l := range ls {
@ -187,7 +192,7 @@ func (c *systemService) GetDirPath(path string) []model.Path {
} else { } else {
dirs = append(dirs, model.Path{Name: "DATA", Path: "/DATA/", IsDir: true, Date: time.Now()}) 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 { func (c *systemService) GetCpuInfo() []cpu.InfoStat {