Skip to content

Commit e8bf543

Browse files
author
Devdutt Shenoi
committed
refactor: fetch_hot_tier_dates
1 parent 13e0f71 commit e8bf543

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/hottier.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ impl HotTierManager {
388388
.join("hottier.manifest.json");
389389
fs::create_dir_all(manifest_path.parent().unwrap()).await?;
390390
fs::write(manifest_path, serde_json::to_vec(&hot_tier_manifest)?).await?;
391+
391392
Ok(file_processed)
392393
}
393394

@@ -413,21 +414,28 @@ impl HotTierManager {
413414
pub async fn fetch_hot_tier_dates(&self, stream: &str) -> Result<Vec<NaiveDate>, HotTierError> {
414415
let mut date_list = Vec::new();
415416
let path = self.hot_tier_path.join(stream);
416-
if path.exists() {
417-
let directories = ReadDirStream::new(fs::read_dir(&path).await?);
418-
let dates: Vec<DirEntry> = directories.try_collect().await?;
419-
for date in dates {
420-
if !date.path().is_dir() {
421-
continue;
422-
}
423-
let date = date.file_name().into_string().unwrap();
424-
date_list.push(
425-
NaiveDate::parse_from_str(date.trim_start_matches("date="), "%Y-%m-%d")
426-
.unwrap(),
427-
);
417+
if !path.exists() {
418+
return Ok(date_list);
419+
}
420+
421+
let directories = fs::read_dir(&path).await?;
422+
let mut dates = ReadDirStream::new(directories);
423+
while let Some(date) = dates.next().await {
424+
let date = date?;
425+
if !date.path().is_dir() {
426+
continue;
428427
}
428+
let date = NaiveDate::parse_from_str(
429+
date.file_name()
430+
.to_string_lossy()
431+
.trim_start_matches("date="),
432+
"%Y-%m-%d",
433+
)
434+
.unwrap();
435+
date_list.push(date);
429436
}
430437
date_list.sort();
438+
431439
Ok(date_list)
432440
}
433441

0 commit comments

Comments
 (0)