Skip to content

Commit a61e096

Browse files
committed
Fix bug when file doesn't exist.
1 parent 47c01cd commit a61e096

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/hibp_lib/buffered_string_writer.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ pub struct BufferedStringWriter {
1515

1616
impl BufferedStringWriter {
1717
pub async fn from_file(filename: &Path) -> Result<Self, std::io::Error> {
18-
let metadata = tokio::fs::metadata(filename).await?;
19-
let writer = if metadata.is_dir() {
18+
let exists = tokio::fs::try_exists(filename).await?;
19+
let is_dir = if exists {
20+
let metadata = tokio::fs::metadata(filename).await?;
21+
metadata.is_dir()
22+
} else {
23+
false
24+
};
25+
let writer = if exists && is_dir {
2026
let mut dir_contents = tokio::fs::read_dir(filename).await?;
2127
if dir_contents.next_entry().await?.is_some() {
2228
return Err(std::io::Error::new(
@@ -49,6 +55,7 @@ impl BufferedStringWriter {
4955
Ok(())
5056
}
5157

58+
#[allow(clippy::get_first)]
5259
pub async fn flush(&mut self, only_contiguous: bool) -> Result<(), std::io::Error> {
5360
// Sort by the 5 character key at the beginning of the file
5461
// This matches the first 5 characters of the first row

src/hibp_lib/sort/row.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub struct MyStruct {
1313
pub hash: String,
1414
}
1515

16+
#[allow(clippy::non_canonical_partial_ord_impl)]
1617
impl PartialOrd for MyStruct {
1718
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
1819
// reverse order (highest to lowest)

0 commit comments

Comments
 (0)