MCPcopy Create free account
hub / github.com/astercloud/aster / createBackup

Method createBackup

pkg/tools/builtin/write.go:226–238  ·  view source on GitHub ↗

createBackup 创建文件备份

(ctx context.Context, filePath, content string, tc *tools.ToolContext)

Source from the content-addressed store, hash-verified

224
225// createBackup 创建文件备份
226func (t *WriteTool) createBackup(ctx context.Context, filePath, content string, tc *tools.ToolContext) string {
227 timestamp := time.Now().Format("20060102_150405")
228 ext := filepath.Ext(filePath)
229 base := strings.TrimSuffix(filePath, ext)
230 backupPath := fmt.Sprintf("%s.backup_%s%s", base, timestamp, ext)
231
232 err := tc.Sandbox.FS().Write(ctx, backupPath, content)
233 if err != nil {
234 return ""
235 }
236
237 return backupPath
238}
239
240func (t *WriteTool) Prompt() string {
241 return `向本地文件系统写入文件内容。

Callers 1

ExecuteMethod · 0.95

Calls 2

WriteMethod · 0.65
FSMethod · 0.65

Tested by

no test coverage detected