feat(tools/file): edit_file atomic + preserve existing mode
This commit is contained in:
1 parent
7ae944f0eb
commit
87f77c76ba
2 files changed
+39
-1
No files matched your search
@@ -91,7 +91,11 @@ func (t *EditFileTool) Execute(_ context.Context, input json.RawMessage) (tool.T
|
||||
|
||||
newContent := strings.Replace(content, in.OldString, in.NewString, 1)
|
||||
|
||||
if err := os.WriteFile(in.Path, []byte(newContent), 0o644); err != nil {
|
||||
mode := os.FileMode(0o600)
|
||||
if info, statErr := os.Stat(in.Path); statErr == nil {
|
||||
mode = info.Mode().Perm()
|
||||
}
|
||||
if err := tool.WriteFileAtomic(in.Path, []byte(newContent), mode); err != nil {
|
||||
return tool.ToolResult{Error: fmt.Sprintf("failed to write file: %v", err)}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user