Skip to content

Appending to a file has no effect, in stable #32801

@progval

Description

@progval
use std::io::Read;
use std::io::Write;
use std::fs::{File, OpenOptions};

fn main() {
    let mut f = File::create("foo.txt").unwrap();
    f.write("bar".as_bytes()).unwrap();
    let mut f = OpenOptions::new().append(true).open("foo.txt").unwrap();
    let _ = f.write_all("baz".as_bytes());
    f.flush().unwrap();

    let mut f = File::open("foo.txt").unwrap();
    let mut content = String::new();
    f.read_to_string(&mut content).unwrap();
    println!("{}", content);
}

Beta and nightly's behavior: prints barbaz
Stable's behavior: prints bar

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions