diff --git a/utils/lock/lock.go b/utils/lock/lock.go index 0e8358809..57c5281af 100644 --- a/utils/lock/lock.go +++ b/utils/lock/lock.go @@ -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" @@ -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 } @@ -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 } diff --git a/utils/lock/utils_unix.go b/utils/osutils/utils_unix.go similarity index 93% rename from utils/lock/utils_unix.go rename to utils/osutils/utils_unix.go index 476ac23ce..c70c907e5 100644 --- a/utils/lock/utils_unix.go +++ b/utils/osutils/utils_unix.go @@ -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 diff --git a/utils/lock/utils_windows.go b/utils/osutils/utils_windows.go similarity index 93% rename from utils/lock/utils_windows.go rename to utils/osutils/utils_windows.go index 504d1c97f..2711fcd1d 100644 --- a/utils/lock/utils_windows.go +++ b/utils/osutils/utils_windows.go @@ -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.