Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export "isProcessRunning" #1126

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions utils/lock/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/jfrog/jfrog-cli-core/v2/utils/osutils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/jfrog/jfrog-client-go/utils/log"
Expand Down Expand Up @@ -129,9 +130,9 @@ func (lock *Lock) removeOtherLockOrWait(otherLock Lock, filesList *[]string) err
log.Debug("Lock hasn't been acquired.")

// Check if the process is running.
// There are two implementation of the 'isProcessRunning'.
// There are two implementation of the 'IsProcessRunning'.
// One for Windows and one for Unix based systems.
running, err := isProcessRunning(otherLock.pid)
running, err := osutils.IsProcessRunning(otherLock.pid)
if err != nil {
return err
}
Expand Down Expand Up @@ -241,7 +242,7 @@ func GetLastLockTimestamp(lockDirPath string) (int64, error) {
lastLock := locks[len(locks)-1]

// If the lock isn't acquired by a running process, an unexpected error was occurred.
running, err := isProcessRunning(lastLock.pid)
running, err := osutils.IsProcessRunning(lastLock.pid)
if err != nil {
return 0, err
}
Expand Down
7 changes: 4 additions & 3 deletions utils/lock/utils_unix.go → utils/osutils/utils_unix.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
//go:build linux || darwin || freebsd
// +build linux darwin freebsd

package lock
package osutils

import (
"github.com/jfrog/jfrog-client-go/utils/log"
"os"
"syscall"

"github.com/jfrog/jfrog-client-go/utils/log"
)

// This file will be compiled only on unix systems.
// Checks if the process is running.
// If error occurs, check if the error is part of the OS permission errors. This means the process is running.
// Else means the process is not running.
func isProcessRunning(pid int) (bool, error) {
func IsProcessRunning(pid int) (bool, error) {
process, err := os.FindProcess(pid)
if err != nil {
return false, err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package lock
package osutils

import (
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"syscall"

"github.com/jfrog/jfrog-client-go/utils/errorutils"
)

// This file will be compiled on Windows.
// Checks if the process can be reached.
// If an error occurs, check if the error is part of the invalid parameter. This means the process is not running.
// Else find the exit code. If the exit code 259 means the process is running.
func isProcessRunning(pid int) (bool, error) {
func IsProcessRunning(pid int) (bool, error) {
process, err := syscall.OpenProcess(syscall.PROCESS_QUERY_INFORMATION, true, uint32(pid))
if err != nil {
// Check if err is of type of syscall.Errno, which is a Windows error number.
Expand Down
Loading