Skip to content

Commit

Permalink
Clean up unnecessary stream wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Mar 15, 2024
1 parent ad8a2c1 commit bfb4034
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/cache_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,16 @@ impl CacheManager {
async fn scan_cache(&self, static_range: Vec<String>, parallelism: usize, verify_cache: bool) -> Result<(), Error> {
let mut dirs = Vec::with_capacity(static_range.len());

let mut root = read_dir(&self.cache_dir).map_ok(ReadDirStream::new).await?;
while let Some(l1) = root.next().await.transpose()? {
let mut root = read_dir(&self.cache_dir).await?;
while let Some(l1) = root.next_entry().await? {
let l1_path = l1.path();
if !l1_path.is_dir() {
warn!("Found unexpected file in cache dir: {}", l1_path.to_str().unwrap_or_default());
continue;
};

let mut l1_stream = read_dir(&l1_path).map_ok(ReadDirStream::new).await?;
while let Some(l2) = l1_stream.next().await.transpose()? {
let mut l1_stream = read_dir(&l1_path).await?;
while let Some(l2) = l1_stream.next_entry().await? {
let l2_path = l2.path();
if !l2_path.is_dir() {
warn!("Found unexpected file in cache dir: {}", l2_path.to_str().unwrap_or_default());
Expand Down Expand Up @@ -262,8 +262,8 @@ impl CacheManager {
let scan_task = stream::iter(dirs)
.map(|dir| async move {
let mut time = FileTime::now();
let mut stream = read_dir(&dir).map_ok(ReadDirStream::new).await?;
while let Some(entry) = stream.next().await.transpose()? {
let mut stream = read_dir(&dir).await?;
while let Some(entry) = stream.next_entry().await? {
let path = entry.path();
let metadata = metadata(&path).await;
if let Err(err) = metadata {
Expand Down Expand Up @@ -396,7 +396,7 @@ impl CacheManager {
while need_free > 0 {
let map = self.cache_date.lock().clone();
let mut dirs = map.iter().collect::<Vec<_>>();
dirs.sort_by(|(_, a), (_, b)| a.cmp(b));
dirs.sort_unstable_by(|(_, a), (_, b)| a.cmp(b));

let files = read_dir(dirs[0].0).map_ok(ReadDirStream::new).await;
if let Err(err) = files {
Expand Down Expand Up @@ -430,7 +430,7 @@ impl CacheManager {
})
.collect()
.await;
files.sort_by(|(_, a, _), (_, b, _)| a.cmp(b));
files.sort_unstable_by(|(_, a, _), (_, b, _)| a.cmp(b));

let mut new_oldest = *cut_off;
for file in files {
Expand Down Expand Up @@ -482,8 +482,8 @@ async fn fix_permission(_path: &Path) {
async fn clean_temp_dir(path: &Path) {
info!("Deleting old temp files");

if let Ok(mut dir) = read_dir(path).map_ok(ReadDirStream::new).await {
while let Some(Ok(file)) = dir.next().await {
if let Ok(mut dir) = read_dir(path).await {
while let Ok(Some(file)) = dir.next_entry().await {
let path = file.path();
if path.is_file() && file.file_name().to_string_lossy().starts_with("proxyfile_") {
debug!("Delete old temp file: {:?}", path);
Expand Down

0 comments on commit bfb4034

Please sign in to comment.