Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions route/periodical_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build darwin
// +build darwin

package route

func SendAllHardwareStatusBySocket() {}

Check failure on line 6 in route/periodical_darwin.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a nested comment explaining why this function is empty or complete the implementation.

See more on https://sonarcloud.io/project/issues?id=IceWhaleTech_CasaOS&issues=AZ8J_00EUniKS_Rlv9VQ&open=AZ8J_00EUniKS_Rlv9VQ&pullRequest=2523
21 changes: 0 additions & 21 deletions service/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
package service

import (
"fmt"

"github.com/IceWhaleTech/CasaOS/service/model"

Check warning on line 14 in service/connections.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove redundant imports of this package; keep only the first occurrence.

See more on https://sonarcloud.io/project/issues?id=IceWhaleTech_CasaOS&issues=AZ8J_02sUniKS_Rlv9VR&open=AZ8J_02sUniKS_Rlv9VR&pullRequest=2523
model2 "github.com/IceWhaleTech/CasaOS/service/model"
"github.com/moby/sys/mount"
"golang.org/x/sys/unix"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -62,23 +58,6 @@
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}
}
28 changes: 28 additions & 0 deletions service/connections_linux.go
Original file line number Diff line number Diff line change
@@ -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)
}
26 changes: 26 additions & 0 deletions service/connections_unsupported.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions service/health_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package service_test

import (
"runtime"
"testing"

"github.com/IceWhaleTech/CasaOS/service"
"github.com/stretchr/testify/assert"
)

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()
Expand Down