Skip to content

Commit

Permalink
style: run rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jan 19, 2024
1 parent 47b35e6 commit 56f53cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 14 additions & 8 deletions rocks-lib/src/manifest/pull_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ use reqwest::Client;
use std::{fs, path::PathBuf};

// TODO(vhyrro): Perhaps cache the manifest somewhere on disk?
pub async fn manifest_from_server(url: String, lua_version: Option<&String>, cache: Option<PathBuf>) -> Result<String> {
let manifest_filename = "manifest".to_string() + &lua_version.map(|s| format!("-{}", s)).unwrap_or_default();
pub async fn manifest_from_server(
url: String,
lua_version: Option<&String>,
cache: Option<PathBuf>,
) -> Result<String> {
let manifest_filename =
"manifest".to_string() + &lua_version.map(|s| format!("-{}", s)).unwrap_or_default();
let url = url + "/" + &manifest_filename;

// Stores a path to the manifest cache (this allows us to operate on a manifest without
// needing to pull it from the luarocks servers each time).
let cache = cache.unwrap_or_else(|| directories::ProjectDirs::from("org", "neorocks", "rocks").unwrap().cache_dir().join(&manifest_filename));
let cache = cache.unwrap_or_else(|| {
directories::ProjectDirs::from("org", "neorocks", "rocks")
.unwrap()
.cache_dir()
.join(&manifest_filename)
});

// Ensure all intermediate directories for the cache file are created (e.g. `~/.cache/rocks/manifest`)
fs::create_dir_all(cache.parent().unwrap())?;
Expand Down Expand Up @@ -41,11 +51,7 @@ pub async fn manifest_from_server(url: String, lua_version: Option<&String>, cac

// If our cache file does not exist then pull the whole manifest.

let new_manifest =
reqwest::get(url)
.await?
.text()
.await?;
let new_manifest = reqwest::get(url).await?.text().await?;

fs::write(&cache, &new_manifest)?;

Expand Down
6 changes: 4 additions & 2 deletions rocks-lib/src/rocks/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ use std::{fs::File, io::Write};
use anyhow::Result;

pub async fn download(rock_name: &String, rock_version: Option<&String>) -> Result<()> {

// TODO(vhyrro): Check if the rock has a `src` attribute, allow custom manifests, allow custom
// URLs, add better error checking. Make sure to use the latest version of a rock if the
// version is ommitted.

let full_rock_name = format!("{}-{}.src.rock", rock_name, rock_version.unwrap());

let rock = reqwest::get(format!("{}/{}", "https://luarocks.org", full_rock_name)).await?.bytes().await?;
let rock = reqwest::get(format!("{}/{}", "https://luarocks.org", full_rock_name))
.await?
.bytes()
.await?;

let mut file = File::create(full_rock_name)?;

Expand Down

0 comments on commit 56f53cf

Please sign in to comment.