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

Method Write

pkg/backends/state.go:144–175  ·  view source on GitHub ↗

Write 实现 BackendProtocol.Write

(ctx context.Context, path, content string)

Source from the content-addressed store, hash-verified

142
143// Write 实现 BackendProtocol.Write
144func (b *StateBackend) Write(ctx context.Context, path, content string) (*WriteResult, error) {
145 b.mu.Lock()
146 defer b.mu.Unlock()
147
148 now := time.Now()
149 lines := strings.Split(content, "\n")
150
151 // 检查文件是否已存在
152 _, exists := b.files[path]
153
154 data := &FileData{
155 Lines: lines,
156 ModifiedAt: now,
157 CreatedAt: now,
158 }
159
160 if exists {
161 // 保留创建时间
162 data.CreatedAt = b.files[path].CreatedAt
163 }
164
165 b.files[path] = data
166
167 return &WriteResult{
168 Error: "", // 空字符串表示成功
169 Path: path,
170 BytesWritten: int64(len(content)),
171 FilesUpdate: map[string]any{
172 path: data,
173 },
174 }, nil
175}
176
177// Edit 实现 BackendProtocol.Edit
178func (b *StateBackend) Edit(ctx context.Context, path, oldStr, newStr string, replaceAll bool) (*EditResult, error) {

Callers 6

BenchmarkBackendWriteFunction · 0.95
TestStateBackendFunction · 0.95
mainFunction · 0.95

Calls

no outgoing calls