Skip to content

Commit

Permalink
Feat: Fix write bug for change
Browse files Browse the repository at this point in the history
  • Loading branch information
fromtheeast710 committed Sep 3, 2024
1 parent 9a83486 commit 97ad437
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use colorz::*;
use std::fs::OpenOptions;
use std::io::{BufReader, BufWriter, Read, Write};
use std::{env, fs, io, process};
use std::{
env, fs,
fs::OpenOptions,
io,
io::{BufReader, BufWriter, Read, Write},
process,
};

const HELP: &str = "LsTodo v0.1.0
Usage: lstodo [COMMAND] [ARGUMENTS]
Expand Down Expand Up @@ -266,13 +270,17 @@ impl LsTodo {
process::exit(1)
}

let file = OpenOptions::new().write(true).open(&self.lstodo_path).expect(&OPEN_ERR);
let file = OpenOptions::new()
.write(true)
.truncate(true)
.open(&self.lstodo_path)
.expect(&OPEN_ERR);

let mut buffer = BufWriter::new(file);

for (p, l) in self.lstodo.iter().enumerate() {
if &(p + 1).to_string() == &args[0] {
let l = format!("{}{}\n", &l[..4], args[1]);
let l = format!("{}{}\n", &l[..4], &args[1]);

buffer.write_all(l.as_bytes()).expect(&WRITE_ERR);
} else {
Expand Down

0 comments on commit 97ad437

Please sign in to comment.