This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-gateway.git


The following commit(s) were added to refs/heads/master by this push:
     new 18a1ddd  fix(agent): detect a desktop app relocated into a version 
directory
18a1ddd is described below

commit 18a1ddd94cd9674dfb25e269550416a1a8322be6
Author: Yang Luo <[email protected]>
AuthorDate: Sun Aug 23 00:20:22 2026 +0800

    fix(agent): detect a desktop app relocated into a version directory
---
 agentprocess/process.go | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/agentprocess/process.go b/agentprocess/process.go
index 2f51f67..ed68afc 100644
--- a/agentprocess/process.go
+++ b/agentprocess/process.go
@@ -179,10 +179,46 @@ func matches(target Target, process Process) bool {
                if samePath(process.Path, candidate) || 
containsPath(process.Command, candidate) {
                        return true
                }
+               if isRelocatedCopy(candidate, process.Path) {
+                       return true
+               }
        }
        return false
 }
 
+// isRelocatedCopy recognises the copy a self-updating desktop app runs: the
+// installed file stays a stub beside one directory per version, and what 
starts
+// is the same program inside the current one.
+func isRelocatedCopy(installed, path string) bool {
+       if installed == "" || path == "" {
+               return false
+       }
+       if !sameName(filepath.Base(installed), filepath.Base(path)) {
+               return false
+       }
+       return isUnder(filepath.Dir(installed), path)
+}
+
+func sameName(left, right string) bool {
+       if runtime.GOOS == "windows" {
+               return strings.EqualFold(left, right)
+       }
+       return left == right
+}
+
+// isUnder reports whether path sits somewhere below dir.
+func isUnder(dir, path string) bool {
+       dir, path = filepath.Clean(dir), filepath.Clean(path)
+       if runtime.GOOS == "windows" {
+               dir, path = strings.ToLower(dir), strings.ToLower(path)
+       }
+       relative, err := filepath.Rel(dir, path)
+       if err != nil {
+               return false
+       }
+       return relative != ".." && !strings.HasPrefix(relative, 
".."+string(filepath.Separator))
+}
+
 func samePath(left, right string) bool {
        if left == "" || right == "" {
                return false


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to