diff options
author | Daniel Schadt <kingdread@gmx.de> | 2024-08-28 20:17:27 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2024-08-28 20:17:27 +0200 |
commit | e30da60a5122791bf6101a31eb5a01969644daef (patch) | |
tree | 61c5d2180dc5ab987cf2cf86e9cbf7e48c3c055a /src | |
parent | 3f0eb33c666afb2924eef835904fe48ef4503d2d (diff) | |
download | ezau-e30da60a5122791bf6101a31eb5a01969644daef.tar.gz ezau-e30da60a5122791bf6101a31eb5a01969644daef.tar.bz2 ezau-e30da60a5122791bf6101a31eb5a01969644daef.zip |
remove zip functionality
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 64 |
2 files changed, 18 insertions, 50 deletions
diff --git a/src/config.rs b/src/config.rs index ad2ee22..8b9211c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -23,6 +23,8 @@ pub struct Config { pub retries: u32, /// Whether ezau should zip non-zipped logs. #[serde(default = "default_zip")] + // We don't use this anymore, but we keep it so old configs can be parsed and we can properly + // inform the user. pub zip: bool, /// Option Discord information for bot postings. pub discord: Option<Discord>, @@ -63,7 +65,7 @@ pub fn load<P: AsRef<Path>>(path: P) -> Result<Config> { } fn default_zip() -> bool { - true + false } fn default_dps_report_upload_url() -> String { diff --git a/src/main.rs b/src/main.rs index 6352bff..b0ddd44 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,17 @@ use std::{ - fs::{self, File}, - io::{BufReader, BufWriter, Read, Write}, path::{Path, PathBuf}, sync::mpsc::channel, thread, time::Duration, }; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{bail, Context, Result}; use clap::Parser; use evtclib::{Compression, Encounter, Log}; use log::{debug, error, info, warn}; use notify::{self, DebouncedEvent, RecursiveMode, Watcher}; use regex::Regex; use serde::Deserialize; -use zip::{CompressionMethod, ZipArchive, ZipWriter}; mod categories; use categories::Categorizable; @@ -48,7 +45,7 @@ enum SubCommand { /// Use the watch mode to automatically handle new logs. /// -/// This watches the given directory for new files and then zips and uploads them. +/// This watches the given directory for new files and then uploads them. #[derive(Parser, Debug, Clone, PartialEq, Eq, Hash)] struct Watch { /// The directory to watch. @@ -104,8 +101,7 @@ fn inner_main(opts: &Opts) -> Result<()> { } fn watch(watch: &Watch, config: &Config) -> Result<()> { - let raw_evtc_re = Regex::new(r"\d{8}-\d{6}(\.evtc)?$").unwrap(); - let zip_evtc_re = Regex::new(r"(\.zip|\.zevtc)$").unwrap(); + let zip_evtc_re = Regex::new(r"(\.evtc\.zip|\.zevtc)$").unwrap(); let (tx, rx) = channel(); let mut watcher = notify::watcher(tx, Duration::from_secs(WATCH_DELAY_SECONDS))?; @@ -118,54 +114,13 @@ fn watch(watch: &Watch, config: &Config) -> Result<()> { debug!("Event: {:?}", event); if let DebouncedEvent::Create(path) = event { let path_str = path.to_str().unwrap(); - // Check if we need to zip it first. - if config.zip && raw_evtc_re.is_match(path_str) { - info!("Zipping up {}", path_str); - zip_file(&path)?; - } else if zip_evtc_re.is_match(path_str) { + if zip_evtc_re.is_match(path_str) { handle_file(config, &path)?; } } } } -fn zip_file(filepath: &Path) -> Result<()> { - let evtc_content = fs::read(filepath)?; - - let filename = filepath - .file_name() - .ok_or_else(|| anyhow!("Path does not have a file name"))? - .to_str() - .ok_or_else(|| anyhow!("Filename is invalid utf-8"))?; - let outname = filepath.with_extension("zevtc"); - let outfile = BufWriter::new(File::create(&outname)?); - let mut zip = ZipWriter::new(outfile); - let options = - zip::write::FileOptions::default().compression_method(CompressionMethod::Deflated); - - zip.start_file(filename, options)?; - zip.write_all(&evtc_content)?; - zip.finish()?.flush()?; - - if !verify_zip(filepath, &outname)? { - warn!("ZIP content mismatch, keeping original file"); - return Ok(()); - } - - fs::remove_file(filepath)?; - Ok(()) -} - -fn verify_zip(original: &Path, zip_path: &Path) -> Result<bool> { - let expected_content = fs::read(original)?; - let mut archive = ZipArchive::new(BufReader::new(File::open(zip_path)?))?; - let mut inner = archive.by_index(0)?; - let mut actual_content = Vec::new(); - inner.read_to_end(&mut actual_content)?; - - Ok(expected_content == actual_content) -} - fn handle_file(config: &Config, filename: &Path) -> Result<()> { if !config.upload { return Ok(()); @@ -257,6 +212,17 @@ fn upload_log(file: &Path, url: &str) -> Result<String> { } fn sanity_check(config: &Config, opts: &Opts) -> Result<()> { + if config.zip { + warn!( + "You have zipping enabled, but zipping is no longer part of ezau. \ + Arcdps automatically zips logs now." + ); + } + if matches!(opts.subcmd, SubCommand::Watch(_)) + && !config.upload + { + bail!("Watching but not uploading. What am I even doing here?"); + } if matches!(opts.subcmd, SubCommand::Watch(_)) && config.discord.is_none() && config.matrix.is_none() |