-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
479 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package state | ||
|
||
const _dirpath = "./.odo" | ||
const _filepath = "./.odo/devstate.json" | ||
const _filepathPid = "./.odo/devstate.%d.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
// Package state gives access to the state of the odo process stored in a local file | ||
// The state of an instance is stored in a file .odo/devstate.${PID}.json. | ||
// For compatibility with previous versions of odo, the `devstate.json` file contains | ||
// the state of the first instance of odo. | ||
package state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package state | ||
|
||
import "fmt" | ||
|
||
type ErrAlreadyRunningOnPlatform struct { | ||
platform string | ||
pid int | ||
} | ||
|
||
func NewErrAlreadyRunningOnPlatform(platform string, pid int) ErrAlreadyRunningOnPlatform { | ||
return ErrAlreadyRunningOnPlatform{ | ||
platform: platform, | ||
pid: pid, | ||
} | ||
} | ||
|
||
func (e ErrAlreadyRunningOnPlatform) Error() string { | ||
return fmt.Sprintf("a session with PID %d is already running on platform %q", e.pid, e.platform) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package state | ||
|
||
import "github.com/redhat-developer/odo/pkg/api" | ||
import ( | ||
"context" | ||
|
||
"github.com/redhat-developer/odo/pkg/api" | ||
) | ||
|
||
type Client interface { | ||
// Init creates a devstate file for the process | ||
Init(ctx context.Context) error | ||
|
||
// SetForwardedPorts sets the forwarded ports in the state file and saves it to the file, updating the metadata | ||
SetForwardedPorts(fwPorts []api.ForwardedPort) error | ||
SetForwardedPorts(ctx context.Context, fwPorts []api.ForwardedPort) error | ||
|
||
// GetForwardedPorts returns the ports forwarded by the current odo dev session | ||
GetForwardedPorts() ([]api.ForwardedPort, error) | ||
GetForwardedPorts(ctx context.Context) ([]api.ForwardedPort, error) | ||
|
||
// SaveExit resets the state file to indicate odo is not running | ||
SaveExit() error | ||
SaveExit(ctx context.Context) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos | ||
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zos | ||
|
||
package state | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
func pidExists(pid int) (bool, error) { | ||
if pid <= 0 { | ||
return false, fmt.Errorf("invalid pid %v", pid) | ||
} | ||
proc, err := os.FindProcess(pid) | ||
if err != nil { | ||
return false, nil | ||
} | ||
err = proc.Signal(syscall.Signal(0)) | ||
if err == nil { | ||
return true, nil | ||
} | ||
if err.Error() == "os: process already finished" { | ||
return false, nil | ||
} | ||
errno, ok := err.(syscall.Errno) | ||
if !ok { | ||
return false, err | ||
} | ||
switch errno { | ||
case syscall.ESRCH: | ||
return false, nil | ||
case syscall.EPERM: | ||
return true, nil | ||
} | ||
return false, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package state | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func pidExists(pid int) (bool, error) { | ||
if pid <= 0 { | ||
return false, fmt.Errorf("invalid pid %v", pid) | ||
} | ||
_, err := os.FindProcess(pid) | ||
if err != nil { | ||
return false, nil | ||
} | ||
return true, nil | ||
} |
Oops, something went wrong.