mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-20 16:27:45 +01:00
only use filemutex for windows (#960)
This commit is contained in:
parent
3763f9429f
commit
e795f75bbb
@ -202,7 +202,7 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
err = waveLock.Unlock()
|
err = waveLock.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error releasing wave lock: %v\n", err)
|
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/spf13/cobra v1.8.1
|
||||||
github.com/wavetermdev/htmltoken v0.1.0
|
github.com/wavetermdev/htmltoken v0.1.0
|
||||||
golang.org/x/crypto v0.28.0
|
golang.org/x/crypto v0.28.0
|
||||||
|
golang.org/x/sys v0.26.0
|
||||||
golang.org/x/term v0.25.0
|
golang.org/x/term v0.25.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,7 +42,6 @@ require (
|
|||||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
go.uber.org/atomic v1.7.0 // indirect
|
||||||
golang.org/x/net v0.29.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
|
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"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alexflint/go-filemutex"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// set by main-server.go
|
// set by main-server.go
|
||||||
@ -41,6 +39,10 @@ const AppPathBinDir = "bin"
|
|||||||
var baseLock = &sync.Mutex{}
|
var baseLock = &sync.Mutex{}
|
||||||
var ensureDirCache = map[string]bool{}
|
var ensureDirCache = map[string]bool{}
|
||||||
|
|
||||||
|
type FDLock interface {
|
||||||
|
Close() error
|
||||||
|
}
|
||||||
|
|
||||||
func IsDevMode() bool {
|
func IsDevMode() bool {
|
||||||
pdev := os.Getenv(WaveDevVarName)
|
pdev := os.Getenv(WaveDevVarName)
|
||||||
return pdev != ""
|
return pdev != ""
|
||||||
@ -200,19 +202,6 @@ func DetermineLocale() string {
|
|||||||
return strings.Replace(truncated, "_", "-", -1)
|
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 {
|
func ClientArch() string {
|
||||||
return fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
|
return fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user