File OS error

This commit is contained in:
Quentin Legot 2023-04-24 14:34:29 +02:00
parent c0990b3fe8
commit c0a340225d

View File

@ -68,36 +68,32 @@ impl<'a> MinecraftClient<'_> {
for (_, i) in self.details.libraries.iter().enumerate() { for (_, i) in self.details.libraries.iter().enumerate() {
let p = i.downloads.artifact.path.clone(); let p = i.downloads.artifact.path.clone();
let mut splited = p.split("/").collect::<Vec<&str>>(); let mut splited = p.split("/").collect::<Vec<&str>>();
splited.pop(); // remove last element let filename = splited.pop().ok_or(anyhow::anyhow!("Invalid filename"))?; // remove last element
let p = splited.join(path::MAIN_SEPARATOR_STR); let p = splited.join(path::MAIN_SEPARATOR_STR);
let p = &lib.join(p); let p = &lib.join(p);
fs::create_dir_all(p).await?; fs::create_dir_all(p).await?;
let url = i.downloads.artifact.url.clone(); let url = i.downloads.artifact.url.clone();
let mut sha = url.clone();
sha.push_str(".sha1");
let sha1 = self.reqwest_client
.get(sha)
.send()
.await?
.text()
.await?;
if sha1 != i.downloads.artifact.sha1 {
bail!("Sha1 hash of a library is invalid, a malicious file might be present on the remote server")
}
let content = self.reqwest_client let content = self.reqwest_client
.get(url) .get(url)
.send() .send()
.await? .await?
.bytes() .bytes()
.await?; .await?;
let mut file = fs::File::create(p).await?; /* let mut hasher = Sha1::new();
hasher.update(&content);
let sha1 = hasher.finalize().to_vec();
if sha1 != i.downloads.artifact.sha1.as_bytes() {
bail!("Sha1 {:?} of {} is invalid, a malicious file might be present on the remote server, should be {}", sha1, i.name, i.downloads.artifact.sha1)
} */
let file = p.join(filename);
let mut file = fs::File::create(file).await?;
file.write_all(&content).await?; file.write_all(&content).await?;
println!("{} downloaded", i.name); println!("{} downloaded", i.name);
} }
Ok(()) Ok(())
} }
/// Filter non necessary librairies for the current OS /// Filter non necessary librairies for the current OS
fn filter_non_necessary_librairies(&mut self) { fn filter_non_necessary_librairies(&mut self) {
self.details.libraries.retain(|e| { Self::should_use_library(e) }); self.details.libraries.retain(|e| { Self::should_use_library(e) });