-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Technical Documentation | ||
|
||
meow | ||
|
||
Everything starts at the [`App`](./src/api/app/mod.rs) struct. | ||
|
||
- `App::collect_sources(&self) -> Vec<Source>` | ||
- `Source::resolve_addons(&App) -> Vec<Addon>` | ||
- `App::collect_addons(&self) -> Vec<Addon>` | ||
- `Addon::resolve_steps(&App) -> Vec<Step>` | ||
- `App::execute_steps(&self, &[Step]) -> Result<()>` | ||
- `App::execute_step(&self, Step) -> Result<StepResult>` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,30 @@ | ||
use crate::api::app::App; | ||
use std::path::Path; | ||
|
||
use anyhow::Result; | ||
|
||
use crate::api::{app::App, models::Addon}; | ||
|
||
impl App { | ||
|
||
pub async fn action_install_jar(&self) -> Result<()> { | ||
Check warning on line 8 in src/api/app/actions/build/mod.rs GitHub Actions / clippymethod `action_install_jar` is never used
|
||
|
||
|
||
Ok(()) | ||
} | ||
Check warning on line 12 in src/api/app/actions/build/mod.rs GitHub Actions / clippyunused `async` for function with no await statements
|
||
|
||
pub async fn action_install_addon(&self, base: &Path, addon: &Addon) -> Result<()> { | ||
let steps = addon.resolve_steps(&self).await?; | ||
Check failure on line 15 in src/api/app/actions/build/mod.rs GitHub Actions / clippythis expression creates a reference which is immediately dereferenced by the compiler
|
||
let dir = base.join(addon.target.as_str()); | ||
self.execute_steps(&dir, &steps).await?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn action_install_addons(&self, base: &Path) -> Result<()> { | ||
let addons = self.collect_addons().await?; | ||
|
||
for addon in &addons { | ||
self.action_install_addon(base, addon).await?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use std::path::Path; | ||
|
||
use anyhow::{anyhow, bail, Result}; | ||
use tokio_stream::StreamExt; | ||
|
||
use crate::api::{models::Addon, step::{CacheLocation, Step, StepResult}, utils::hashing::get_best_hash}; | ||
Check warning on line 6 in src/api/app/step.rs GitHub Actions / clippyunused imports: `CacheLocation`, `models::Addon`
|
||
|
||
use super::App; | ||
|
||
impl App { | ||
pub async fn execute_steps(&self, dir: &Path, steps: &[Step]) -> Result<()> { | ||
for step in steps { | ||
let res = self.execute_step(dir, step).await?; | ||
|
||
if res == StepResult::Skip { | ||
break; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub async fn execute_step(&self, dir: &Path, step: &Step) -> Result<StepResult> { | ||
match step { | ||
Step::CacheCheck(metadata) => { | ||
if let Some(cache) = &metadata.cache { | ||
Check warning on line 26 in src/api/app/step.rs GitHub Actions / clippyunused variable: `cache`
|
||
|
||
} | ||
|
||
Ok(StepResult::Continue) | ||
}, | ||
|
||
Step::Download { url, metadata } => { | ||
let cache_destination = self.cache.loc(metadata.cache.as_ref()); | ||
let output_destination = dir.join(&metadata.filename); | ||
|
||
let res = self.http_get(url).await?; | ||
|
||
let content_length = res.content_length(); | ||
match (metadata.size, content_length) { | ||
(Some(a), Some(b)) if a != b => { | ||
bail!("Mismatched Content-Length! Expected {a}, recieved {b}"); | ||
}, | ||
_ => {}, | ||
} | ||
|
||
let mut stream = res.bytes_stream(); | ||
|
||
let mut hasher = get_best_hash(&metadata.hashes).map(|(format, content)| { | ||
(format, format.get_digest(), content) | ||
}); | ||
|
||
let target_destination = cache_destination.as_ref().unwrap_or(&output_destination); | ||
tokio::fs::create_dir_all(target_destination.parent().ok_or(anyhow!("No parent"))?).await?; | ||
|
||
let target_file = tokio::fs::File::create(&target_destination).await?; | ||
let mut target_writer = tokio::io::BufWriter::new(target_file); | ||
|
||
while let Some(item) = stream.try_next().await? { | ||
if let Some((_, ref mut digest, _ )) = hasher { | ||
digest.update(&item); | ||
} | ||
|
||
tokio::io::copy(&mut item.as_ref(), &mut target_writer).await?; | ||
} | ||
|
||
if let Some((_, hasher, content)) = hasher { | ||
let hash = hex::encode(&hasher.finalize()); | ||
|
||
if hash != content { | ||
bail!("Mismatched hash!"); | ||
} | ||
} | ||
|
||
if let Some(cache_destination) = cache_destination { | ||
tokio::fs::create_dir_all(output_destination.parent().ok_or(anyhow!("No parent"))?).await?; | ||
tokio::fs::copy(&cache_destination, &output_destination).await?; | ||
} | ||
|
||
println!("Downloaded {}", metadata.filename); | ||
|
||
Ok(StepResult::Continue) | ||
}, | ||
|
||
Step::Execute => Ok(StepResult::Continue), | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod models; |
This file was deleted.