More resolved TODOs

This commit is contained in:
AlexSSD7 2023-08-31 20:17:55 +01:00
commit 07e3705f09
4 changed files with 26 additions and 15 deletions

View file

@ -103,13 +103,6 @@ func init() {
runCmd.Flags().StringVar(&shareBackendFlag, "share-backend", defaultShareType, "Specifies the file share backend to use. The default value is OS-specific.")
runCmd.Flags().StringVar(&shareListenIPFlag, "share-listen", share.GetDefaultListenIPStr(), "Specifies the IP to bind the network share port to. NOTE: For FTP, changing the bind address is not enough to connect remotely. You should also specify --ftp-extip.")
smbExternDefault := false
if runtime.GOOS == "windows" {
smbExternDefault = true
}
runCmd.Flags().StringVar(&ftpExtIPFlag, "ftp-extip", share.GetDefaultListenIPStr(), "Specifies the external IP the FTP server should advertise.")
runCmd.Flags().BoolVar(&smbUseExternAddrFlag, "smb-extern", smbExternDefault, "Specifies whether Linsk emulate external networking for the VM's SMB server. This is the default for Windows as there is no way to specify ports in Windows SMB client.")
// TODO: log the use of smbUseExternAddrFlag when SMB is not enabled.
runCmd.Flags().BoolVar(&smbUseExternAddrFlag, "smb-extern", share.IsSMBExtModeDefault(), "Specifies whether Linsk emulate external networking for the VM's SMB server. This is the default for Windows as there is no way to specify ports in Windows SMB client.")
}

View file

@ -7,12 +7,6 @@ import (
"log/slog"
)
var defaultListenIP = net.ParseIP("127.0.0.1")
func GetDefaultListenIPStr() string {
return defaultListenIP.String()
}
type UserConfiguration struct {
listenIP net.IP
ftpExtIP net.IP
@ -49,6 +43,10 @@ func (rc RawUserConfiguration) Process(backend string, warnLogger *slog.Logger)
}
}
if rc.SMBExtMode && backend != "smb" && !IsSMBExtModeDefault() {
slog.Warn("SMB external mode specification is ineffective with non-SMB backends")
}
return &UserConfiguration{
listenIP: listenIP,
ftpExtIP: ftpExtIP,

16
share/defaults.go Normal file
View file

@ -0,0 +1,16 @@
package share
import (
"net"
"runtime"
)
func IsSMBExtModeDefault() bool {
return runtime.GOOS == "windows1"
}
var defaultListenIP = net.ParseIP("127.0.0.1")
func GetDefaultListenIPStr() string {
return defaultListenIP.String()
}

View file

@ -42,9 +42,13 @@ func (s *Storage) ReleaseNetTapAllocation(tapName string) error {
return errors.Wrap(err, "get alloc file path")
}
// TODO: Check what happens the file doesn't exist. It should not return an error.
err = os.Remove(allocFilePath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
s.logger.Warn("Attempted to remove non-existent tap allocation", "tap-name", tapName)
return nil
}
return errors.Wrap(err, "remove alloc file")
}