Write 实现 BackendProtocol.Write
(ctx context.Context, path, content string)
| 135 | |
| 136 | // Write 实现 BackendProtocol.Write |
| 137 | func (b *StoreBackend) Write(ctx context.Context, path, content string) (*WriteResult, error) { |
| 138 | now := time.Now() |
| 139 | lines := strings.Split(content, "\n") |
| 140 | |
| 141 | // 检查文件是否已存在 |
| 142 | existingData, err := b.loadFileData(ctx, path) |
| 143 | createdAt := now |
| 144 | if err == nil && existingData != nil { |
| 145 | createdAt = existingData.CreatedAt |
| 146 | } |
| 147 | |
| 148 | data := &FileData{ |
| 149 | Lines: lines, |
| 150 | CreatedAt: createdAt, |
| 151 | ModifiedAt: now, |
| 152 | } |
| 153 | |
| 154 | // 保存到 Store |
| 155 | if err := b.saveFileData(ctx, path, data); err != nil { |
| 156 | return nil, err |
| 157 | } |
| 158 | |
| 159 | return &WriteResult{ |
| 160 | Error: "", // 空字符串表示成功 |
| 161 | Path: path, |
| 162 | BytesWritten: int64(len(content)), |
| 163 | FilesUpdate: nil, // StoreBackend 不需要返回状态更新 |
| 164 | }, nil |
| 165 | } |
| 166 | |
| 167 | // Edit 实现 BackendProtocol.Edit |
| 168 | func (b *StoreBackend) Edit(ctx context.Context, path, oldStr, newStr string, replaceAll bool) (*EditResult, error) { |
nothing calls this directly
no test coverage detected