mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
only use filemutex for windows (#960)
This commit is contained in:
parent
3763f9429f
commit
e795f75bbb
@ -202,7 +202,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
err = waveLock.Unlock()
|
||||
err = waveLock.Close()
|
||||
if err != nil {
|
||||
log.Printf("error releasing wave lock: %v\n", err)
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -23,6 +23,7 @@ require (
|
||||
github.com/spf13/cobra v1.8.1
|
||||
github.com/wavetermdev/htmltoken v0.1.0
|
||||
golang.org/x/crypto v0.28.0
|
||||
golang.org/x/sys v0.26.0
|
||||
golang.org/x/term v0.25.0
|
||||
)
|
||||
|
||||
@ -41,7 +42,6 @@ require (
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
golang.org/x/net v0.29.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/kevinburke/ssh_config => github.com/wavetermdev/ssh_config v0.0.0-20240306041034-17e2087ebde2
|
||||
|
30
pkg/wavebase/wavebase-posix.go
Normal file
30
pkg/wavebase/wavebase-posix.go
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright 2024, Command Line Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
//go:build !windows
|
||||
|
||||
package wavebase
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func AcquireWaveLock() (FDLock, error) {
|
||||
homeDir := GetWaveHomeDir()
|
||||
lockFileName := filepath.Join(homeDir, WaveLockFile)
|
||||
log.Printf("[base] acquiring lock on %s\n", lockFileName)
|
||||
fd, err := os.OpenFile(lockFileName, os.O_RDWR|os.O_CREATE, 0600)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = unix.Flock(int(fd.Fd()), unix.LOCK_EX|unix.LOCK_NB)
|
||||
if err != nil {
|
||||
fd.Close()
|
||||
return nil, err
|
||||
}
|
||||
return fd, nil
|
||||
}
|
29
pkg/wavebase/wavebase-win.go
Normal file
29
pkg/wavebase/wavebase-win.go
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2024, Command Line Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
//go:build windows
|
||||
|
||||
package wavebase
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/alexflint/go-filemutex"
|
||||
)
|
||||
|
||||
func AcquireWaveLock() (FDLock, error) {
|
||||
homeDir := GetWaveHomeDir()
|
||||
lockFileName := filepath.Join(homeDir, WaveLockFile)
|
||||
log.Printf("[base] acquiring lock on %s\n", lockFileName)
|
||||
m, err := filemutex.New(lockFileName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("filemutex new error: %w", err)
|
||||
}
|
||||
err = m.TryLock()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("filemutex trylock error: %w", err)
|
||||
}
|
||||
return m, nil
|
||||
}
|
@ -17,8 +17,6 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/alexflint/go-filemutex"
|
||||
)
|
||||
|
||||
// set by main-server.go
|
||||
@ -41,6 +39,10 @@ const AppPathBinDir = "bin"
|
||||
var baseLock = &sync.Mutex{}
|
||||
var ensureDirCache = map[string]bool{}
|
||||
|
||||
type FDLock interface {
|
||||
Close() error
|
||||
}
|
||||
|
||||
func IsDevMode() bool {
|
||||
pdev := os.Getenv(WaveDevVarName)
|
||||
return pdev != ""
|
||||
@ -200,19 +202,6 @@ func DetermineLocale() string {
|
||||
return strings.Replace(truncated, "_", "-", -1)
|
||||
}
|
||||
|
||||
func AcquireWaveLock() (*filemutex.FileMutex, error) {
|
||||
homeDir := GetWaveHomeDir()
|
||||
lockFileName := filepath.Join(homeDir, WaveLockFile)
|
||||
log.Printf("[base] acquiring lock on %s\n", lockFileName)
|
||||
m, err := filemutex.New(lockFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = m.TryLock()
|
||||
return m, err
|
||||
}
|
||||
|
||||
func ClientArch() string {
|
||||
return fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user