Simplify error handling for file lock in tunnel command

pull/15834/head
Om Saran 2023-02-15 15:52:09 -06:00 committed by Steven Powell
parent d8a920fd39
commit 09e6aff951
1 changed files with 5 additions and 6 deletions

View File

@ -136,12 +136,11 @@ func mustLockOrExit() {
_, err := os.OpenFile(tunnelLockPath, os.O_RDWR|os.O_TRUNC, 0600)
if err != nil {
if os.IsNotExist(err) {
_, err = os.Create(tunnelLockPath)
if err != nil {
exit.Error(reason.SvcTunnelStart, fmt.Sprintf("error creating lock for tunnel file (%s)", tunnelLockPath), err)
}
} else {
if !os.IsNotExist(err) {
exit.Error(reason.SvcTunnelStart, fmt.Sprintf("error opening lock file for tunnel file (%s)", tunnelLockPath), err)
}
_, err = os.Create(tunnelLockPath)
if err != nil {
exit.Error(reason.SvcTunnelStart, fmt.Sprintf("error creating lock for tunnel file (%s)", tunnelLockPath), err)
}
}