Skip to content

Commit

Permalink
Handling both EOF and EOL cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hetdagli234 authored and lukacan committed Aug 16, 2024
1 parent bb4291e commit 41066bd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/client/src/test_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,20 @@ impl TestGenerator {
return;
}
}
// Check if the file ends with a newline
let mut file = File::open(&gitignore_path)?;
let mut buf = [0; 1];
file.seek(io::SeekFrom::End(-1))?;
file.read_exact(&mut buf)?;

let file = OpenOptions::new().append(true).open(gitignore_path);

if let Ok(mut file) = file {
writeln!(file, "\n{}", ignored_path)?;
if buf[0] == b'\n' {
writeln!(file, "{}", ignored_path)?;
} else {
writeln!(file, "\n{}", ignored_path)?;
}
println!("{FINISH} [{GIT_IGNORE}] update with [{ignored_path}]");
}
} else {
Expand Down

0 comments on commit 41066bd

Please sign in to comment.