Skip to content

Commit

Permalink
Make sure the fstab ends with a newline
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamc committed Dec 5, 2024
1 parent 3cb1128 commit d1d9644
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/action/macos/create_fstab_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ impl Action for CreateFstabEntry {
current_fstab_lines.push(fstab_entry(&uuid))
}

if current_fstab_lines.last().map(|s| s.as_ref()) != Some("") {
// Don't leave the file without a trailing newline
current_fstab_lines.push("".into());
}

let updated_buf = current_fstab_lines.join("\n");

write_atomic(fstab_path, &updated_buf)
Expand Down Expand Up @@ -129,7 +134,7 @@ impl Action for CreateFstabEntry {
.await
.map_err(|e| Self::error(ActionErrorKind::Read(fstab_path.to_owned(), e)))?;

let updated_buf = fstab_buf
let mut current_fstab_lines = fstab_buf
.lines()
.filter_map(|line| {
// Delete nix-installer entries with a "prelude" comment
Expand All @@ -147,10 +152,14 @@ impl Action for CreateFstabEntry {
Some(line)
}
})
.collect::<Vec<&str>>()
.join("\n");
.collect::<Vec<&str>>();

write_atomic(fstab_path, &updated_buf)
if current_fstab_lines.last() != Some(&"") {
// Don't leave the file without a trailing newline
current_fstab_lines.push("");
}

write_atomic(fstab_path, &current_fstab_lines.join("\n"))
.await
.map_err(Self::error)?;

Expand Down

0 comments on commit d1d9644

Please sign in to comment.