Skip to content

Commit 4af43a5

Browse files
author
Devdutt Shenoi
committed
DRY: get_stream_path_for_date
1 parent 592da07 commit 4af43a5

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

src/hottier.rs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ impl HotTierManager {
7878
.clone()
7979
.map(|hot_tier_path| {
8080
INSTANCE.get_or_init(|| {
81-
std::fs::create_dir_all(&hot_tier_path).unwrap();
82-
HotTierManager {
83-
filesystem: LocalFileSystem::new(),
84-
hot_tier_path,
85-
}
81+
std::fs::create_dir_all(&hot_tier_path).unwrap();
82+
HotTierManager {
83+
filesystem: LocalFileSystem::new(),
84+
hot_tier_path,
85+
}
8686
})
8787
})
8888
}
@@ -391,9 +391,8 @@ impl HotTierManager {
391391
.sort_by_key(|file| file.file_path.clone());
392392
// write the manifest file to the hot tier directory
393393
let manifest_path = self
394-
.hot_tier_path
395-
.join(stream)
396-
.join(format!("date={}/hottier.manifest.json", date));
394+
.get_stream_path_for_date(stream, &date)
395+
.join("hottier.manifest.json");
397396
fs::create_dir_all(manifest_path.parent().unwrap()).await?;
398397
fs::write(manifest_path, serde_json::to_vec(&hot_tier_manifest)?).await?;
399398
Ok(file_processed)
@@ -408,7 +407,7 @@ impl HotTierManager {
408407
dates: &[NaiveDate],
409408
) -> Result<(), HotTierError> {
410409
for date in dates.iter() {
411-
let path = self.hot_tier_path.join(format!("{}/date={}", stream, date));
410+
let path = self.get_stream_path_for_date(stream, &date);
412411
if path.exists() {
413412
fs::remove_dir_all(path.clone()).await?;
414413
}
@@ -562,11 +561,7 @@ impl HotTierManager {
562561
let mut delete_successful = false;
563562
let dates = self.fetch_hot_tier_dates(stream).await?;
564563
'loop_dates: for date in dates {
565-
let date_str = date.to_string();
566-
let path = &self
567-
.hot_tier_path
568-
.join(stream)
569-
.join(format!("date={}", date_str));
564+
let path = self.get_stream_path_for_date(stream, &date);
570565
if !path.exists() {
571566
continue;
572567
}
@@ -588,12 +583,7 @@ impl HotTierManager {
588583

589584
'loop_files: while let Some(file_to_delete) = manifest.files.pop() {
590585
let file_size = file_to_delete.file_size;
591-
let path_to_delete = CONFIG
592-
.options
593-
.hot_tier_storage_path
594-
.as_ref()
595-
.unwrap()
596-
.join(&file_to_delete.file_path);
586+
let path_to_delete = self.hot_tier_path.join(&file_to_delete.file_path);
597587

598588
if path_to_delete.exists() {
599589
if let (Some(download_date_time), Some(delete_date_time)) = (
@@ -670,11 +660,7 @@ impl HotTierManager {
670660
}
671661

672662
for date in date_list {
673-
let path = self
674-
.hot_tier_path
675-
.join(stream)
676-
.join(format!("date={}", date));
677-
663+
let path = self.get_stream_path_for_date(stream, &date);
678664
let hours_dir = ReadDirStream::new(fs::read_dir(&path).await?);
679665
let mut hours: Vec<DirEntry> = hours_dir.try_collect().await?;
680666
hours.retain(|entry| {

0 commit comments

Comments
 (0)