package spm import ( "fmt" "math/rand" "os" "path/filepath" "sync" "time" ) var ( tempDirOnce sync.Once tempDirPath string ) // GetTempDir generates or retrieves a unique temp directory. func GetTempDir() string { tempDirOnce.Do(func() { // Generate a unique temp directory name rand.Seed(time.Now().UnixNano()) tempDirPath = filepath.Join(os.TempDir(), fmt.Sprintf("spm_temp_%d", rand.Intn(1000000))) // Ensure the directory exists if err := os.MkdirAll(tempDirPath, os.ModePerm); err != nil { fmt.Printf("[ERROR] Failed to create temp directory: %v\n", err) } else { fmt.Printf("[INFO] Using temp directory: %s\n", tempDirPath) } }) return tempDirPath }