Skip to content

Commit

Permalink
♻️ Remove password field from FileManager
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanTsune committed Aug 12, 2024
1 parent 2097e97 commit 8ce3f99
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/file_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ const ROOT_INODE: Inode = 1;

pub(crate) struct FileManager {
archive_path: PathBuf,
password: Option<String>,
tree: Tree<Inode>,
files: HashMap<Inode, File>,
node_ids: HashMap<Inode, NodeId>,
Expand All @@ -177,30 +176,28 @@ impl FileManager {
pub(crate) fn new(archive_path: PathBuf, password: Option<String>) -> Self {
let mut mamager = Self {
archive_path,
password,
tree: TreeBuilder::new().build(),
files: HashMap::new(),
node_ids: HashMap::new(),
last_inode: ROOT_INODE,
};
mamager.populate().unwrap();
mamager.populate(password.as_deref()).unwrap();
mamager
}

fn populate(&mut self) -> io::Result<()> {
fn populate(&mut self, password: Option<&str>) -> io::Result<()> {
self.add_root_file(File::root(ROOT_INODE))?;
let file = fs::File::open(&self.archive_path)?;
let mut archive = Archive::read_header(file)?;
let password = self.password.clone();
for entry in archive.entries_with_password(password.as_deref()) {
for entry in archive.entries_with_password(password) {
let entry = entry?;
let parents = entry.header().path().as_path().parent();
let parent = if let Some(parents) = parents {
self.make_dir_all(parents, ROOT_INODE)?
} else {
ROOT_INODE
};
let file = File::from_entry(self.next_inode(), entry, password.as_ref());
let file = File::from_entry(self.next_inode(), entry, password);
self.add_or_update_file(file, parent)?;
}
Ok(())
Expand Down

0 comments on commit 8ce3f99

Please sign in to comment.