@@ -5,33 +5,39 @@ import (
55 "path/filepath"
66)
77
8- // GetConfigDir returns the user's config directory for cagent
9- // Falls back to temp directory if home directory cannot be determined
8+ // GetConfigDir returns the user's config directory for cagent.
9+ //
10+ // If the home directory cannot be determined, it falls back to a directory
11+ // under the system temporary directory. This is a best-effort fallback and
12+ // not intended to be a security boundary.
1013func GetConfigDir () string {
1114 homeDir , err := os .UserHomeDir ()
1215 if err != nil {
1316 // Fallback to temp directory
14- return filepath .Join (os .TempDir (), ".cagent-config" )
17+ return filepath .Clean ( filepath . Join (os .TempDir (), ".cagent-config" ) )
1518 }
16- return filepath .Join (homeDir , ".config" , "cagent" )
19+ return filepath .Clean ( filepath . Join (homeDir , ".config" , "cagent" ) )
1720}
1821
19- // GetDataDir returns the user's data directory for cagent (caches, content, logs)
20- // Falls back to temp directory if home directory cannot be determined
22+ // GetDataDir returns the user's data directory for cagent (caches, content, logs).
23+ //
24+ // If the home directory cannot be determined, it falls back to a directory
25+ // under the system temporary directory.
2126func GetDataDir () string {
2227 homeDir , err := os .UserHomeDir ()
2328 if err != nil {
24- return filepath .Join (os .TempDir (), ".cagent" )
29+ return filepath .Clean ( filepath . Join (os .TempDir (), ".cagent" ) )
2530 }
26- return filepath .Join (homeDir , ".cagent" )
31+ return filepath .Clean ( filepath . Join (homeDir , ".cagent" ) )
2732}
2833
29- // GetHomeDir returns the user's home directory
30- // Returns empty string if the home directory cannot be determined
34+ // GetHomeDir returns the user's home directory.
35+ //
36+ // Returns an empty string if the home directory cannot be determined.
3137func GetHomeDir () string {
3238 homeDir , err := os .UserHomeDir ()
3339 if err != nil {
3440 return ""
3541 }
36- return homeDir
42+ return filepath . Clean ( homeDir )
3743}
0 commit comments