Skip to content

Commit

Permalink
Fix bug in writing to file with no extension
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed Sep 3, 2024
1 parent a13133d commit 5197c7c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ fn main() {

for file in &args.files {
let mut logs = Vec::<Log>::new();
if let Some(text) = read(file, &mut logs) {
let new_text = format_file(&text, file, &args, &mut logs);
if let Some((file, text)) = read(file, &mut logs) {
let new_text = format_file(&text, &file, &args, &mut logs);
exit_code = process_output(
&args, file, &text, &new_text, exit_code, &mut logs,
&args, &file, &text, &new_text, exit_code, &mut logs,
);
} else {
exit_code = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Cli {
}

/// Add a missing extension and read the file
pub fn read(file: &str, logs: &mut Vec<Log>) -> Option<String> {
pub fn read(file: &str, logs: &mut Vec<Log>) -> Option<(String, String)> {
// check if file has an accepted extension
let has_ext = EXTENSIONS.iter().any(|e| file.ends_with(e));
// if no valid extension, try adding .tex
Expand All @@ -57,7 +57,7 @@ pub fn read(file: &str, logs: &mut Vec<Log>) -> Option<String> {
new_file.push_str(".tex");
};
if let Ok(text) = fs::read_to_string(&new_file) {
return Some(text);
return Some((new_file, text));
}
if has_ext {
record_file_log(logs, Error, file, "Could not open file.");
Expand Down

0 comments on commit 5197c7c

Please sign in to comment.