Skip to content

Commit

Permalink
truncate
Browse files Browse the repository at this point in the history
  • Loading branch information
daschr committed Sep 20, 2023
1 parent 0d04a9b commit 63ce59b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Hosts {
let path: PathBuf = path.into();
let fd = OpenOptions::new()
.read(true)
.write(true)
.write(true) // just opening it rw here to check, if we can do it
.open(path.clone())?;
let mut sections: HashMap<Option<String>, Vec<String>> = HashMap::new();

Expand Down Expand Up @@ -71,7 +71,10 @@ impl Hosts {
}

pub fn write(&mut self) -> Result<(), IoError> {
let fd = OpenOptions::new().write(true).open(self.file.clone())?;
let fd = OpenOptions::new()
.write(true)
.truncate(true)
.open(self.file.clone())?;
let mut writer = BufWriter::new(fd);

if let Some(entries) = self.sections.remove(&None) {
Expand Down

0 comments on commit 63ce59b

Please sign in to comment.