Skip to content

Commit

Permalink
Merge pull request #72 from Jupeyy/pr_tar_fix_dir
Browse files Browse the repository at this point in the history
Fix tar should ignore dirs itself
  • Loading branch information
Jupeyy authored Jan 16, 2025
2 parents fdc3980 + 991ea72 commit 3407f1c
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions game/client-containers/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
sync::Arc,
time::Duration,
};
use tar::EntryType;
use tokio::sync::Semaphore;

use anyhow::anyhow;
Expand Down Expand Up @@ -484,9 +485,10 @@ where
}
_ => {
log::warn!(
"Unsupported resource type {} \
"Unsupported resource type {} for {} \
could not be validated",
file_ty
file_ty,
file_name,
);
return false;
}
Expand Down Expand Up @@ -542,15 +544,36 @@ where
let mut file = tar::Archive::new(std::io::Cursor::new(file));
match file.entries() {
Ok(entries) => entries
.map(|entry| {
.filter_map(|entry| {
entry
.map_err(|err| anyhow::anyhow!(err))
.map(|mut entry| {
let path = entry.path().map(|path| path.to_path_buf())?;
let mut file: Vec<_> = Default::default();
entry.read_to_end(&mut file).map(|_| (path, file))
let ty = entry.header().entry_type();
if let EntryType::Regular = ty {
Some(
entry
.path()
.map(|path| path.to_path_buf())
.map_err(|err| anyhow::anyhow!(err))
.and_then(|path| {
let mut file: Vec<_> = Default::default();

entry
.read_to_end(&mut file)
.map(|_| (path, file))
.map_err(|err| anyhow::anyhow!(err))
}),
)
} else if matches!(ty, EntryType::Directory) {
None
} else {
Some(Err(anyhow!(
"The tar reader expects files & dictionaries only"
)))
}
})
.map_err(|err| anyhow::anyhow!(err))
.and_then(|val| anyhow::Ok(val?))
.transpose()
.map(|r| r.and_then(|r| r))
})
.collect::<anyhow::Result<HashMap<_, _>>>(),
Err(err) => Err(anyhow::anyhow!(err)),
Expand Down

0 comments on commit 3407f1c

Please sign in to comment.