2021-11-09 10:57:50 +00:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
2022-08-15 03:37:21 +00:00
|
|
|
"fmt"
|
2022-06-29 03:09:58 +00:00
|
|
|
"os"
|
2022-05-13 10:12:26 +00:00
|
|
|
"strings"
|
2022-08-18 03:18:27 +00:00
|
|
|
"time"
|
2021-11-09 10:57:50 +00:00
|
|
|
|
2022-08-15 03:37:21 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/samba"
|
2021-11-09 10:57:50 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
2022-08-18 03:18:27 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
2021-11-09 10:57:50 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS/service"
|
2022-08-18 03:18:27 +00:00
|
|
|
"go.uber.org/zap"
|
2021-11-09 10:57:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func InitFunction() {
|
2022-08-18 03:18:27 +00:00
|
|
|
go InitNetworkMount()
|
2021-11-09 10:57:50 +00:00
|
|
|
}
|
2022-08-15 03:37:21 +00:00
|
|
|
func InitNetworkMount() {
|
2022-08-18 03:18:27 +00:00
|
|
|
time.Sleep(time.Second * 10)
|
2022-08-15 03:37:21 +00:00
|
|
|
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))
|
2022-08-18 03:18:27 +00:00
|
|
|
loger.Error("mount samba err", zap.Any("err", err), zap.Any("info", connection))
|
2022-08-15 03:37:21 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|