diff --git a/route/periodical_darwin.go b/route/periodical_darwin.go new file mode 100644 index 000000000..37a296ebb --- /dev/null +++ b/route/periodical_darwin.go @@ -0,0 +1,6 @@ +//go:build darwin +// +build darwin + +package route + +func SendAllHardwareStatusBySocket() {} diff --git a/service/connections.go b/service/connections.go index 52034fab1..752d4b28f 100644 --- a/service/connections.go +++ b/service/connections.go @@ -11,12 +11,8 @@ package service import ( - "fmt" - "github.com/IceWhaleTech/CasaOS/service/model" model2 "github.com/IceWhaleTech/CasaOS/service/model" - "github.com/moby/sys/mount" - "golang.org/x/sys/unix" "gorm.io/gorm" ) @@ -62,23 +58,6 @@ func (s *connectionsStruct) DeleteConnection(id string) { s.db.Where("id= ?", id).Delete(&model.ConnectionsDBModel{}) } -func (s *connectionsStruct) MountSmaba(username, host, directory, port, mountPoint, password string) error { - err := unix.Mount( - fmt.Sprintf("//%s/%s", host, directory), - mountPoint, - "cifs", - unix.MS_NOATIME|unix.MS_NODEV|unix.MS_NOSUID, - fmt.Sprintf("username=%s,password=%s", username, password), - ) - return err - // str := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;MountCIFS " + username + " " + host + " " + directory + " " + port + " " + mountPoint + " " + password) - // return str -} - -func (s *connectionsStruct) UnmountSmaba(mountPoint string) error { - return mount.Unmount(mountPoint) -} - func NewConnectionsService(db *gorm.DB) ConnectionsService { return &connectionsStruct{db: db} } diff --git a/service/connections_linux.go b/service/connections_linux.go new file mode 100644 index 000000000..77b020902 --- /dev/null +++ b/service/connections_linux.go @@ -0,0 +1,28 @@ +//go:build linux +// +build linux + +package service + +import ( + "fmt" + + "github.com/moby/sys/mount" + "golang.org/x/sys/unix" +) + +func (s *connectionsStruct) MountSmaba(username, host, directory, port, mountPoint, password string) error { + err := unix.Mount( + fmt.Sprintf("//%s/%s", host, directory), + mountPoint, + "cifs", + unix.MS_NOATIME|unix.MS_NODEV|unix.MS_NOSUID, + fmt.Sprintf("username=%s,password=%s", username, password), + ) + return err + // str := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;MountCIFS " + username + " " + host + " " + directory + " " + port + " " + mountPoint + " " + password) + // return str +} + +func (s *connectionsStruct) UnmountSmaba(mountPoint string) error { + return mount.Unmount(mountPoint) +} diff --git a/service/connections_unsupported.go b/service/connections_unsupported.go new file mode 100644 index 000000000..a6dfb0b40 --- /dev/null +++ b/service/connections_unsupported.go @@ -0,0 +1,26 @@ +//go:build !linux +// +build !linux + +package service + +import "runtime" + +func (s *connectionsStruct) MountSmaba(username, host, directory, port, mountPoint, password string) error { + return unsupportedMountError() +} + +func (s *connectionsStruct) UnmountSmaba(mountPoint string) error { + return unsupportedMountError() +} + +func unsupportedMountError() error { + return &mountUnsupportedError{platform: runtime.GOOS} +} + +type mountUnsupportedError struct { + platform string +} + +func (e *mountUnsupportedError) Error() string { + return "samba mounts are only supported on linux, not " + e.platform +} diff --git a/service/health_test.go b/service/health_test.go index c64537a8b..85798776a 100644 --- a/service/health_test.go +++ b/service/health_test.go @@ -1,6 +1,7 @@ package service_test import ( + "runtime" "testing" "github.com/IceWhaleTech/CasaOS/service" @@ -8,6 +9,10 @@ import ( ) func TestPorts(t *testing.T) { + if runtime.GOOS != "linux" { + t.Skip("port.ListPortsInUse reads /proc/net, which is only available on linux") + } + service := service.NewHealthService() tcpPorts, udpPorts, err := service.Ports()