Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/opencode/src/tool/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import DESCRIPTION from "./write.txt"
import { Bus } from "../bus"
import { File } from "../file"
import { FileWatcher } from "../file/watcher"
import { Format } from "../format"
import { FileTime } from "../file/time"
import { Filesystem } from "../util/filesystem"
import { Instance } from "../project/instance"
Expand Down Expand Up @@ -42,9 +41,10 @@ export const WriteTool = Tool.define("write", {
},
})

await Filesystem.write(filepath, params.content)
await Format.file(filepath)
Bus.publish(File.Event.Edited, { file: filepath })
await Filesystem.write(filepath, params.content, 0o644)
await Bus.publish(File.Event.Edited, {
file: filepath,
})
await Bus.publish(FileWatcher.Event.Updated, {
file: filepath,
event: exists ? "change" : "add",
Expand Down
4 changes: 4 additions & 0 deletions packages/opencode/src/util/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export namespace Filesystem {
try {
if (mode) {
await writeFile(p, content, { mode })
// writeFile mode is still filtered by process umask for newly created files,
// and won't update mode for existing files. Force the requested mode explicitly.
await chmod(p, mode)
} else {
await writeFile(p, content)
}
Expand All @@ -70,6 +73,7 @@ export namespace Filesystem {
await mkdir(dirname(p), { recursive: true })
if (mode) {
await writeFile(p, content, { mode })
await chmod(p, mode)
} else {
await writeFile(p, content)
}
Expand Down
Loading