Try cleaning up paths before adding them
This commit is contained in:
34
main.go
34
main.go
@@ -32,6 +32,10 @@ func init() {
|
|||||||
log.Lmicroseconds|log.Lshortfile)
|
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() {
|
func main() {
|
||||||
currentPath := os.Getenv("PATH")
|
currentPath := os.Getenv("PATH")
|
||||||
paths := strings.Split(currentPath, ";")
|
paths := strings.Split(currentPath, ";")
|
||||||
@@ -75,10 +79,36 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, path := range alwaysInclude {
|
for _, path := range alwaysInclude {
|
||||||
if !contains(cleanPaths, path) {
|
path = filepath.Clean(path)
|
||||||
cleanPaths = append(cleanPaths, 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, ";")
|
newPath := strings.Join(cleanPaths, ";")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user