package route import ( "fmt" "os" "strings" "time" "github.com/IceWhaleTech/CasaOS/pkg/samba" "github.com/IceWhaleTech/CasaOS/pkg/utils/file" "github.com/IceWhaleTech/CasaOS/pkg/utils/loger" "github.com/IceWhaleTech/CasaOS/service" "go.uber.org/zap" ) func InitFunction() { go InitNetworkMount() } func InitNetworkMount() { time.Sleep(time.Second * 10) connections := service.MyService.Connections().GetConnectionsList() for _, v := range connections { connection := service.MyService.Connections().GetConnectionByID(fmt.Sprint(v.ID)) directories, err := samba.GetSambaSharesList(connection.Host, connection.Port, connection.Username, connection.Password) if err != nil { service.MyService.Connections().DeleteConnection(fmt.Sprint(connection.ID)) loger.Error("mount samba err", zap.Any("err", err), zap.Any("info", connection)) continue } baseHostPath := "/mnt/" + connection.Host mountPointList := service.MyService.System().GetDirPath(baseHostPath) for _, v := range mountPointList { service.MyService.Connections().UnmountSmaba(v.Path) } os.RemoveAll(baseHostPath) file.IsNotExistMkDir(baseHostPath) for _, v := range directories { mountPoint := baseHostPath + "/" + v file.IsNotExistMkDir(mountPoint) service.MyService.Connections().MountSmaba(connection.Username, connection.Host, v, connection.Port, mountPoint, connection.Password) } connection.Directories = strings.Join(directories, ",") service.MyService.Connections().UpdateConnection(&connection) } }