Init
This commit is contained in:
commit
d9dae02ffc
17 changed files with 1742 additions and 0 deletions
32
spm/tempdir.go
Normal file
32
spm/tempdir.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue