os: use stringslite.TrimSuffix

Change-Id: Ie51a1550181c9478455c757fc82a88bc549ad687
GitHub-Last-Rev: 4b6ffd043b0f2acebb8d2477da17a4d1dfe708ed
GitHub-Pull-Request: golang/go#67153
Reviewed-on: https://go-review.googlesource.com/c/go/+/583095
Auto-Submit: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
changes/95/583095/3
apocelipes 2024-05-04 10:17:30 +00:00 committed by Gopher Robot
parent c3dff93a8c
commit 619b419a4b
1 changed files with 2 additions and 9 deletions

View File

@ -8,6 +8,7 @@ package os
import (
"errors"
"internal/stringslite"
"runtime"
)
@ -25,13 +26,5 @@ func executable() (string, error) {
// When the executable has been deleted then Readlink returns a
// path appended with " (deleted)".
return stringsTrimSuffix(path, " (deleted)"), err
}
// stringsTrimSuffix is the same as strings.TrimSuffix.
func stringsTrimSuffix(s, suffix string) string {
if len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix {
return s[:len(s)-len(suffix)]
}
return s
return stringslite.TrimSuffix(path, " (deleted)"), err
}