CasaOS - A simple, easy-to-use, elegant open-source Personal Cloud system.
Remount if the configuration file already exists (#877)
linkfbfcc2c43ab1
diff --git a/build/sysroot/usr/lib/systemd/system/casaos.service b/build/sysroot/usr/lib/systemd/system/casaos.serviceindex 7a48e63..332062b 100644--- a/build/sysroot/usr/lib/systemd/system/casaos.service+++ b/build/sysroot/usr/lib/systemd/system/casaos.service@@ -1,5 +1,6 @@[Unit]After=casaos-message-bus.service+After=rclone.serviceConditionFileNotEmpty=/etc/casaos/casaos.confDescription=CasaOS Main Servicediff --git a/go.mod b/go.modindex dba5b7c..eb258f6 100644--- a/go.mod+++ b/go.mod@@ -42,6 +42,7 @@ require (go.uber.org/zap v1.24.0golang.org/x/crypto v0.5.0golang.org/x/oauth2 v0.3.0+ golang.org/x/sync v0.0.0-20210220032951-036812b2e83cgorm.io/gorm v1.24.3gotest.tools v2.2.0+incompatible)diff --git a/go.sum b/go.sumindex 9843af1..46a5eba 100644--- a/go.sum+++ b/go.sum@@ -323,6 +323,7 @@ golang.org/x/oauth2 v0.3.0 h1:6l90koy8/LaBLmLu8jpHeHexzMwEita0zFfYlggy2F8=golang.org/x/oauth2 v0.3.0/go.mod h1:rQrIauxkUhJ6CuwEXwymO2/eh4xz2ZWF1nBkcxS+tGk=golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=+golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=diff --git a/main.go b/main.goindex 8b1cd09..9612685 100644--- a/main.go+++ b/main.go@@ -147,7 +147,6 @@ func main() {route.V2APIPath,route.V2DocPath,route.V3FilePath,- route.V4DirPath,}for _, apiPath := range routers {err = service.MyService.Gateway().CreateRoute(&model.Route{diff --git a/route/periodical.go b/route/periodical.goindex 2883acb..223b6ad 100644--- a/route/periodical.go+++ b/route/periodical.go@@ -66,9 +66,10 @@ func SendAllHardwareStatusBySocket() {body["sys_net"] = newNetsystemTempMap := service.MyService.Notify().GetSystemTempMap()- for k, v := range systemTempMap {- body[k] = v- }+ systemTempMap.Range(func(key, value interface{}) bool {+ body[key.(string)] = value+ return true+ })service.MyService.Notify().SendNotify("casaos:system:utilization", body)}diff --git a/route/v1/recover.go b/route/v1/recover.goindex 792556e..581a85e 100644--- a/route/v1/recover.go+++ b/route/v1/recover.go@@ -58,12 +58,8 @@ func GetRecoverStorage(c *gin.Context) {username = fileutil.NameAccumulation(username, "/mnt")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>`)- service.MyService.Storage().CheckAndMountByName(username)- notify["status"] = "warn"- notify["message"] = "The same configuration has been added"- service.MyService.Notify().SendNotify("casaos:file:recover", notify)- return+ service.MyService.Storage().UnmountStorage("/mnt/" + username)+ service.MyService.Storage().DeleteConfigByName(username)}dmap := make(map[string]string)dmap["client_id"] = add.ClientID@@ -115,12 +111,8 @@ func GetRecoverStorage(c *gin.Context) {username = fileutil.NameAccumulation(username, "/mnt")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>`)- service.MyService.Storage().CheckAndMountByName(username)- notify["status"] = "warn"- notify["message"] = "The same configuration has been added"- service.MyService.Notify().SendNotify("casaos:file:recover", notify)- return+ service.MyService.Storage().UnmountStorage("/mnt/" + username)+ service.MyService.Storage().DeleteConfigByName(username)}dmap := make(map[string]string)dmap["client_id"] = add.AppKeydiff --git a/route/v1/system.go b/route/v1/system.goindex ba42c46..28a2e22 100644--- a/route/v1/system.go+++ b/route/v1/system.go@@ -232,9 +232,11 @@ func GetSystemUtilization(c *gin.Context) {}data["net"] = newNet- for k, v := range service.MyService.Notify().GetSystemTempMap() {- data[k] = v- }+ systemMap := service.MyService.Notify().GetSystemTempMap()+ systemMap.Range(func(key, value interface{}) bool {+ data[key.(string)] = value+ return true+ })c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})}diff --git a/route/v2.go b/route/v2.goindex afb5a00..1bf7ba5 100644--- a/route/v2.go+++ b/route/v2.go@@ -69,8 +69,8 @@ func InitV2Router() http.Handler {e.Use(echo_middleware.JWTWithConfig(echo_middleware.JWTConfig{Skipper: func(c echo.Context) bool {- // return c.RealIP() == "::1" || c.RealIP() == "127.0.0.1"- return true+ return c.RealIP() == "::1" || c.RealIP() == "127.0.0.1"+ //return true},ParseTokenFunc: func(token string, c echo.Context) (interface{}, error) {claims, code := jwt.Validate(token)diff --git a/service/notify.go b/service/notify.goindex 8df6e51..47fa7bf 100644--- a/service/notify.go+++ b/service/notify.go@@ -15,6 +15,7 @@ import ("github.com/IceWhaleTech/CasaOS/service/model""github.com/IceWhaleTech/CasaOS/types""go.uber.org/zap"+ "golang.org/x/sync/syncmap"socketio "github.com/googollee/go-socket.io""github.com/gorilla/websocket"@@ -36,17 +37,18 @@ type NotifyServer interface {//SendInstallAppBySocket(app notifyCommon.Application)SendNotify(name string, message map[string]interface{})SettingSystemTempData(message map[string]interface{})- GetSystemTempMap() map[string]interface{}+ GetSystemTempMap() syncmap.Map}type notifyServer struct {db *gorm.DB- SystemTempMap map[string]interface{}+ SystemTempMap syncmap.Map //[string]interface{}}func (i *notifyServer) SettingSystemTempData(message map[string]interface{}) {for k, v := range message {- i.SystemTempMap[k] = v+ i.SystemTempMap.Store(k, v)+ //i.SystemTempMap[k] = v}}@@ -340,10 +342,10 @@ func SendMeg() {// }// }-func (i *notifyServer) GetSystemTempMap() map[string]interface{} {+func (i *notifyServer) GetSystemTempMap() syncmap.Map {return i.SystemTempMap}func NewNotifyService(db *gorm.DB) NotifyServer {- return ¬ifyServer{db: db, SystemTempMap: make(map[string]interface{})}+ return ¬ifyServer{db: db, SystemTempMap: syncmap.Map{}}}