Skip to content

Commit

Permalink
Merge branch version/0-43-0-RC1 to adopt changes from PR #2962
Browse files Browse the repository at this point in the history
  • Loading branch information
as-builds committed Dec 20, 2023
2 parents 46eb148 + 08f1013 commit bf556cd
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions internal/osutils/osutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"

"github.com/shirou/gopsutil/v3/process"

Expand Down Expand Up @@ -138,21 +139,30 @@ func GetProcessesInUse(dir string) map[string]int32 {
return inUse
}

var wg sync.WaitGroup
var mutex sync.Mutex
if runtime.GOOS != "linux" {
dir = strings.ToLower(dir) // Windows and macOS filesystems are case-insensitive
}
for _, p := range procs {
exe, err := p.Exe()
if err != nil {
continue // probably a permission error; ignore
}
exeToCompare := exe
if runtime.GOOS != "linux" {
exeToCompare = strings.ToLower(exeToCompare) // Windows and macOS filesystems are case-insensitive
}
if strings.Contains(exeToCompare, dir) {
inUse[exe] = p.Pid
}
wg.Add(1)
go func(p *process.Process) {
defer wg.Done()
exe, err := p.Exe()
if err != nil {
return // probably a permission error; ignore
}
exeToCompare := exe
if runtime.GOOS != "linux" {
exeToCompare = strings.ToLower(exeToCompare) // Windows and macOS filesystems are case-insensitive
}
if strings.Contains(exeToCompare, dir) {
mutex.Lock()
inUse[exe] = p.Pid
mutex.Unlock()
}
}(p)
}
wg.Wait()
return inUse
}

0 comments on commit bf556cd

Please sign in to comment.