Skip to content

Commit

Permalink
clippy && fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlan404 committed Dec 13, 2023
1 parent fa2fe6c commit ecaede6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
19 changes: 11 additions & 8 deletions src/app/feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,23 @@ impl Prefix {
Prefix::Exported => " Exported",
Prefix::Rendered => " Rendered",
Prefix::Unpacked => " Unpacked",
Prefix::Packed => " Packed",
Prefix::Packed => " Packed",

Prefix::Error => " ⚠ Error",
Prefix::Warning => " ⚠ Warn",
Prefix::Info => " 🛈 Info",
Prefix::Debug => " debug",
Prefix::Error => " ⚠ Error",
Prefix::Warning => " ⚠ Warn",
Prefix::Info => " 🛈 Info",
Prefix::Debug => " debug",
}
}

pub fn styled(self) -> StyledObject<&'static str> {
match self {
Prefix::Downloaded | Prefix::Imported | Prefix::Exported | Prefix::Rendered | Prefix::Packed | Prefix::Unpacked => {
style(self.as_str()).green().bold()
}
Prefix::Downloaded
| Prefix::Imported
| Prefix::Exported
| Prefix::Rendered
| Prefix::Packed
| Prefix::Unpacked => style(self.as_str()).green().bold(),
Prefix::Copied | Prefix::Skipped => style(self.as_str()).green(),
Prefix::Error => style(self.as_str()).red().bold(),
Prefix::Warning | Prefix::SkippedWarning => style(self.as_str()).yellow().bold(),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/world/pack.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use crate::app::App;
use anyhow::Result;

#[derive(clap::Args)]
pub struct Args {
Expand Down
53 changes: 37 additions & 16 deletions src/interop/worlds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::{path::{PathBuf, Path}, time::Duration};
use std::{
path::{Path, PathBuf},
time::Duration,
};

use anyhow::{Result, anyhow, bail, Context};
use anyhow::{anyhow, bail, Context, Result};
use indicatif::ProgressBar;
use pathdiff::diff_paths;
use walkdir::WalkDir;
Expand All @@ -12,15 +15,23 @@ pub struct WorldsAPI<'a>(pub &'a App);

impl<'a> WorldsAPI<'a> {
pub fn unpack(&self, world: &str) -> Result<()> {
let spinner = self.0.multi_progress.add(ProgressBar::new_spinner())
let spinner = self
.0
.multi_progress
.add(ProgressBar::new_spinner())
.with_message(format!("Unzipping world '{world}'..."));
spinner.enable_steady_tick(Duration::from_millis(250));
let zip_path = self.0.server.path.join("worlds").join(format!("{world}.zip"));
let zip_path = self
.0
.server
.path
.join("worlds")
.join(format!("{world}.zip"));

if !zip_path.exists() {
bail!("worlds/{world}.zip doesnt exist");
}

self.unzip(&zip_path, &self.0.server.path.join("server").join(world))?;

spinner.finish();
Expand All @@ -30,13 +41,15 @@ impl<'a> WorldsAPI<'a> {
}

#[allow(clippy::unused_self)]
pub fn unzip(&self, zipfile: &PathBuf, output: &PathBuf) -> Result<()> {
let file = std::fs::File::open(&zipfile)
.context(format!("Opening zip file: {}", zipfile.display()))?;
let mut archive = zip::ZipArchive::new(file)
.context("Opening zip archive")?;
pub fn unzip(&self, zip_archive_path: &PathBuf, output: &Path) -> Result<()> {
let file = std::fs::File::open(zip_archive_path)
.context(format!("Opening zip file: {}", zip_archive_path.display()))?;
let mut archive = zip::ZipArchive::new(file).context("Opening zip archive")?;

let files = archive.file_names().map(ToOwned::to_owned).collect::<Vec<_>>();
let files = archive
.file_names()
.map(ToOwned::to_owned)
.collect::<Vec<_>>();

for filename in files {
if filename.ends_with('/') {
Expand All @@ -55,15 +68,23 @@ impl<'a> WorldsAPI<'a> {
}

pub fn pack(&self, world: &str) -> Result<()> {
let spinner = self.0.multi_progress.add(ProgressBar::new_spinner())
let spinner = self
.0
.multi_progress
.add(ProgressBar::new_spinner())
.with_message(format!("Zipping world '{world}'..."));

spinner.enable_steady_tick(Duration::from_millis(250));

let input_path = self.0.server.path.join("server").join(world);
let output_path = self.0.server.path.join("worlds").join(format!("{world}.zip"));
let output_path = self
.0
.server
.path
.join("worlds")
.join(format!("{world}.zip"));
std::fs::create_dir_all(self.0.server.path.join("worlds"))?;
let output_file = std::fs::File::create(&output_path)?;
let output_file = std::fs::File::create(output_path)?;

let mut zip = zip::ZipWriter::new(output_file);

Expand All @@ -76,8 +97,8 @@ impl<'a> WorldsAPI<'a> {
})?;

let source = entry.path();
let diffed_paths = diff_paths(source, &input_path)
.ok_or(anyhow!("Cannot diff paths"))?;
let diffed_paths =
diff_paths(source, &input_path).ok_or(anyhow!("Cannot diff paths"))?;

if entry.file_type().is_dir() {
zip.add_directory(diffed_paths.to_string_lossy(), FileOptions::default())?;
Expand Down

0 comments on commit ecaede6

Please sign in to comment.