fix: ollie-9p write/rdwr propagate clunk errors

The 9P protocol returns write handler errors via Rclunk, not Rwrite.
cmdWrite and cmdRdwr were using defer fid.Close() which discarded the
error. Now they check fid.Close() return value and exit non-zero on
failure, allowing the GUI to detect rename errors.
This commit is contained in:
Levi Neely 2026-08-03 18:04:12 +02:00
parent 76c6021d16
commit ff3f8c8819
1 changed files with 13 additions and 2 deletions

View File

@ -193,10 +193,15 @@ func cmdWrite(path string) {
if err != nil {
fatalf("open %s: %v", path, err)
}
defer fid.Close()
if _, err := io.Copy(fid, os.Stdin); err != nil {
fid.Close()
fatalf("write %s: %v", path, err)
}
// Close flushes buffered writes; errors (e.g., validation failures)
// are returned via Rclunk.
if err := fid.Close(); err != nil {
fatalf("close %s: %v", path, err)
}
}
func cmdRdwr(path string) {
@ -205,24 +210,30 @@ func cmdRdwr(path string) {
if err != nil {
fatalf("open %s: %v", path, err)
}
defer fid.Close()
// Write stdin
data, err := io.ReadAll(os.Stdin)
if err != nil {
fid.Close()
fatalf("read stdin: %v", err)
}
if _, err := fid.Write(data); err != nil {
fid.Close()
fatalf("write %s: %v", path, err)
}
// Seek back to 0 and read response
if _, err := fid.Seek(0, 0); err != nil {
fid.Close()
fatalf("seek %s: %v", path, err)
}
if _, err := io.Copy(os.Stdout, fid); err != nil {
fid.Close()
fatalf("read %s: %v", path, err)
}
if err := fid.Close(); err != nil {
fatalf("close %s: %v", path, err)
}
}
func cmdStat(path string) {