Try cleaning up paths before adding them

This commit is contained in:
2024-10-02 22:50:09 +02:00
parent 885f92aa0f
commit 38b833582a

34
main.go
View File

@@ -32,6 +32,10 @@ func init() {
log.Lmicroseconds|log.Lshortfile)
}
// I actually don't even know if this works or not.........
// Changes can be seen in windows system properties fucking thing
// But not in new terminals
// And rerunning the program even with a new terminal will
func main() {
currentPath := os.Getenv("PATH")
paths := strings.Split(currentPath, ";")
@@ -75,9 +79,35 @@ func main() {
}
for _, path := range alwaysInclude {
if !contains(cleanPaths, path) {
cleanPaths = append(cleanPaths, path)
path = filepath.Clean(path)
if !filepath.IsAbs(path) {
var err error
path, err = filepath.Abs(path)
if err != nil {
Error.Printf("error getting absolute path for %v: %v", path, err)
return
}
}
path = filepath.FromSlash(path)
fhandle, err := os.Open(path)
if err != nil {
if os.IsNotExist(err) {
Warning.Printf("Path %v does not exist", path)
continue
}
Warning.Printf("Error opening path %v: %v", path, err)
continue
}
fhandle.Close()
if slices.Contains(cleanPaths, path) {
Warning.Printf("Path %v already exists in cleanPaths", path)
continue
}
cleanPaths = append(cleanPaths, path)
log.Printf("Added path %v", path)
}
newPath := strings.Join(cleanPaths, ";")