Browse Source

Solve the problem of local application import failure

LinkLeong 2 years ago
parent
commit
438b8a1dd2
6 changed files with 58 additions and 2 deletions
  1. 8 1
      CHANGELOG.md
  2. 5 0
      model/sys_common.go
  3. 34 0
      route/init.go
  4. 1 0
      service/docker.go
  5. 9 0
      service/system.go
  6. 1 1
      types/system.go

+ 8 - 1
CHANGELOG.md

@@ -18,7 +18,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Fixed
 
-## [0.3.7]
+## [0.3.7.1] 2022-11-04
+
+### Fixed
+
+- Fix memory leak issue ([#658](https://github.com/IceWhaleTech/CasaOS/issues/658)[#646](https://github.com/IceWhaleTech/CasaOS/issues/646))
+- Solve the problem of local application import failure ([#490](https://github.com/IceWhaleTech/CasaOS/issues/490))
+
+## [0.3.7] 2022-10-28
 
 ### Added
 - [Storage] Disk merge (Beta), you can merge multiple disks into a single storage space (currently you need to enable this feature from the command line)

+ 5 - 0
model/sys_common.go

@@ -74,3 +74,8 @@ type FileSetting struct {
 	ShareDir    []string `json:"share_dir" delim:"|"`
 	DownloadDir string   `json:"download_dir"`
 }
+type BaseInfo struct {
+	Hash    string `json:"i"`
+	Version string `json:"v"`
+	Channel string `json:"c,omitempty"`
+}

+ 34 - 0
route/init.go

@@ -1,21 +1,55 @@
 package route
 
 import (
+	"encoding/json"
 	"fmt"
 	"os"
 	"strings"
 	"time"
 
+	"github.com/IceWhaleTech/CasaOS/model"
+	"github.com/IceWhaleTech/CasaOS/pkg/config"
 	"github.com/IceWhaleTech/CasaOS/pkg/samba"
+	"github.com/IceWhaleTech/CasaOS/pkg/utils/encryption"
 	"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
 	"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
 	"github.com/IceWhaleTech/CasaOS/service"
+	"github.com/IceWhaleTech/CasaOS/types"
 	"go.uber.org/zap"
 )
 
 func InitFunction() {
 	go InitNetworkMount()
+	go InitInfo()
 }
+
+func InitInfo() {
+	mb := model.BaseInfo{}
+	if file.Exists(config.AppInfo.DBPath + "/baseinfo.conf") {
+		err := json.Unmarshal(file.ReadFullFile(config.AppInfo.DBPath+"/baseinfo.conf"), &mb)
+		if err != nil {
+			loger.Error("baseinfo.conf", zap.String("error", err.Error()))
+		}
+	}
+	if file.Exists("/etc/CHANNEL") {
+		channel := file.ReadFullFile("/etc/CHANNEL")
+		mb.Channel = string(channel)
+	}
+	mac, err := service.MyService.System().GetMacAddress()
+	if err != nil {
+		loger.Error("GetMacAddress", zap.String("error", err.Error()))
+	}
+	mb.Hash = encryption.GetMD5ByStr(mac)
+	mb.Version = types.CURRENTVERSION
+	os.Remove(config.AppInfo.DBPath + "/baseinfo.conf")
+	by, err := json.Marshal(mb)
+	if err != nil {
+		loger.Error("init info err", zap.Any("err", err))
+		return
+	}
+	file.WriteToFullPath(by, config.AppInfo.DBPath+"/baseinfo.conf", 0o666)
+}
+
 func InitNetworkMount() {
 	time.Sleep(time.Second * 10)
 	connections := service.MyService.Connections().GetConnectionsList()

+ 1 - 0
service/docker.go

@@ -560,6 +560,7 @@ func (ds *dockerService) DockerContainerCreate(m model.CustomizationPostData, id
 	//container, err := cli.ContainerCreate(context.Background(), info.Config, info.HostConfig, &network.NetworkingConfig{info.NetworkSettings.Networks}, nil, info.Name)
 
 	hostConfig.Mounts = volumes
+	hostConfig.Binds = []string{}
 	hostConfig.Privileged = m.Privileged
 	hostConfig.CapAdd = m.CapAdd
 	hostConfig.NetworkMode = container.NetworkMode(m.NetworkModel)

+ 9 - 0
service/system.go

@@ -50,9 +50,18 @@ type SystemService interface {
 	IsServiceRunning(name string) bool
 	GetCPUTemperature() int
 	GetCPUPower() map[string]string
+	GetMacAddress() (string, error)
 }
 type systemService struct{}
 
+func (c *systemService) GetMacAddress() (string, error) {
+	interfaces, err := net.Interfaces()
+	if err != nil {
+		return "", err
+	}
+	inter := interfaces[0]
+	return inter.HardwareAddr, nil
+}
 func (c *systemService) MkdirAll(path string) (int, error) {
 	_, err := os.Stat(path)
 	if err == nil {

+ 1 - 1
types/system.go

@@ -9,6 +9,6 @@
  */
 package types
 
-const CURRENTVERSION = "0.3.7"
+const CURRENTVERSION = "0.3.7.1"
 
 const BODY = " "