¸ÄÓñ¾»ú¶ÀÁ¢ CA£¬»ָ´ CLI TLS УÑ飬±£»¤ƾ¾ÝÓëÅäÖò¢·¢±£´档 д Cursor Êý¾ݡ¢»Ự·¾¶¡¢´úÀíÉúÃüÖÜÆڡ¢ģÐÍÇëÇóÓë Skills Îļþ²Ù×÷¡£ Ϊ¶ÀÁ¢ Tab ·þÎñÔö¼ӿͻ§¶˼øȨ£¬Éý¼¶ÒÀÀµÓ빤¾ßÁ´£¬ÍêÉƷ¢²¼ԪÐÅϢͬ²½¡£ Ñé֤£ºÁ½¸ö Go ģ¿éµIJâÊÔ/vet¡¢¹ؼüģ¿é race¡¢ǰ¶˲âÊÔ/Éú²ú¹¹½¨/Éó¼ơ¢ Go ¿ɴï©¶´ɨÃèÓë macOS/Linux ¿ÉÐÐģ¿齻²æ±àÒë¾ùͨ¹ý¡£ Windows ¸ôÀëÆô¶¯ͨ¹ý£»δÍê³ɵĵã»÷ðÑ̺ÍԭÉúƽ̨Ñé֤¼ûÉó²鱨¸档
85 lines
2.1 KiB
Go
85 lines
2.1 KiB
Go
package appdata
|
|
|
|
import (
|
|
"cursor/internal/securefile"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func ensureAssistantHome() error {
|
|
migrateLegacyAssistantHome()
|
|
if err := securefile.PrivateDir(RootDir()); err != nil {
|
|
return fmt.Errorf("create assistant home: %w", err)
|
|
}
|
|
if err := securefile.PrivateDir(DataRootPath()); err != nil {
|
|
return fmt.Errorf("create data root: %w", err)
|
|
}
|
|
if err := securefile.PrivateDir(HistoryRootPath()); err != nil {
|
|
return fmt.Errorf("create history root: %w", err)
|
|
}
|
|
if err := securefile.PrivateDir(RulesRootPath()); err != nil {
|
|
return fmt.Errorf("create rules root: %w", err)
|
|
}
|
|
if err := securefile.PrivateDir(LogsRootPath()); err != nil {
|
|
return fmt.Errorf("create logs root: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func EnsureAssistantHome() error {
|
|
return ensureAssistantHome()
|
|
}
|
|
|
|
func migrateLegacyAssistantHome() {
|
|
legacyRoot := legacyRootDir()
|
|
copyLegacyFile(filepath.Join(legacyRoot, "config.yaml"), filepath.Join(RootDir(), "config.yaml"))
|
|
copyLegacyRules(filepath.Join(legacyRoot, "rules"), RulesRootPath())
|
|
_ = os.RemoveAll(legacyRoot)
|
|
}
|
|
|
|
func copyLegacyRules(sourceRoot string, targetRoot string) {
|
|
_ = filepath.Walk(sourceRoot, func(path string, info os.FileInfo, err error) error {
|
|
if err != nil || info == nil {
|
|
return nil
|
|
}
|
|
rel, err := filepath.Rel(sourceRoot, path)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
targetPath := filepath.Join(targetRoot, rel)
|
|
if info.IsDir() {
|
|
_ = os.MkdirAll(targetPath, info.Mode().Perm())
|
|
return nil
|
|
}
|
|
if !info.Mode().IsRegular() {
|
|
return nil
|
|
}
|
|
copyLegacyFile(path, targetPath)
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func copyLegacyFile(sourcePath string, targetPath string) {
|
|
sourceFile, err := os.Open(sourcePath)
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer sourceFile.Close()
|
|
|
|
info, err := sourceFile.Stat()
|
|
if err != nil || !info.Mode().IsRegular() {
|
|
return
|
|
}
|
|
if err := os.MkdirAll(filepath.Dir(targetPath), 0o755); err != nil {
|
|
return
|
|
}
|
|
targetFile, err := os.OpenFile(targetPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, info.Mode().Perm())
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer targetFile.Close()
|
|
_, _ = io.Copy(targetFile, sourceFile)
|
|
}
|