VecDeque makes more sense to maintain order of operations

This commit is contained in:
ellieplayswow 2025-02-03 15:51:42 +00:00
parent a4d7a377d3
commit b4dae4bfa8

View file

@ -6,6 +6,7 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::Arc, sync::Arc,
}; };
use std::collections::VecDeque;
use std::fmt::{Formatter}; use std::fmt::{Formatter};
use tokio::sync::{mpsc, Mutex as TokioMutex}; use tokio::sync::{mpsc, Mutex as TokioMutex};
use walkdir::WalkDir; use walkdir::WalkDir;
@ -119,7 +120,7 @@ fn zip_extract<R: io::Read + io::Seek, P: AsRef<Path>>(
let mut files_by_unix_mode = Vec::new(); let mut files_by_unix_mode = Vec::new();
let mut buffer = vec![0; 4 * 1024 * 1024]; let mut buffer = vec![0; 4 * 1024 * 1024];
let total_files = archive.len(); let total_files = archive.len();
let mut pending_directory_creates = Vec::new(); let mut pending_directory_creates = VecDeque::new();
for i in 0..total_files { for i in 0..total_files {
controller controller
@ -139,7 +140,7 @@ fn zip_extract<R: io::Read + io::Seek, P: AsRef<Path>>(
let outpath = directory.as_ref().join(filepath); let outpath = directory.as_ref().join(filepath);
if file.is_dir() { if file.is_dir() {
pending_directory_creates.push(outpath.clone()); pending_directory_creates.push_back(outpath.clone());
continue; continue;
} }
let symlink_target = if file.is_symlink() && (cfg!(unix) || cfg!(windows)) { let symlink_target = if file.is_symlink() && (cfg!(unix) || cfg!(windows)) {
@ -152,7 +153,7 @@ fn zip_extract<R: io::Read + io::Seek, P: AsRef<Path>>(
drop(file); drop(file);
if let Some(target) = symlink_target { if let Some(target) = symlink_target {
// create all pending dirs // create all pending dirs
while let Some(pending_dir) = pending_directory_creates.pop() { while let Some(pending_dir) = pending_directory_creates.pop_front() {
make_writable_dir_all(pending_dir)?; make_writable_dir_all(pending_dir)?;
} }
@ -196,7 +197,7 @@ fn zip_extract<R: io::Read + io::Seek, P: AsRef<Path>>(
}.map_err(|e| e)?; }.map_err(|e| e)?;
// create all pending dirs // create all pending dirs
while let Some(pending_dir) = pending_directory_creates.pop() { while let Some(pending_dir) = pending_directory_creates.pop_front() {
make_writable_dir_all(pending_dir)?; make_writable_dir_all(pending_dir)?;
} }