From dab98a7a67059d6daee053ebf4dbbee78b4c9a28 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Fri, 3 Apr 2020 20:10:06 +0200 Subject: [PATCH] Fix warnings on Linux --- src/clipboard/linux.rs | 6 ++- src/config/mod.rs | 73 ++++++++++++++++++------------------ src/config/runtime.rs | 33 ++++++++--------- src/context/linux.rs | 9 ++--- src/engine.rs | 27 ++------------ src/event/mod.rs | 4 +- src/extension/clipboard.rs | 4 +- src/keyboard/mod.rs | 2 +- src/main.rs | 26 ++++++------- src/matcher/mod.rs | 2 +- src/matcher/scrolling.rs | 2 +- src/package/default.rs | 76 +++++++++++++++++++------------------- src/package/zip.rs | 8 ++-- src/render/default.rs | 5 +-- src/sysdaemon.rs | 18 ++++----- src/utils.rs | 24 ++++++------ 16 files changed, 147 insertions(+), 172 deletions(-) diff --git a/src/clipboard/linux.rs b/src/clipboard/linux.rs index 8fb76e1..b3e4e4d 100644 --- a/src/clipboard/linux.rs +++ b/src/clipboard/linux.rs @@ -19,7 +19,7 @@ use std::process::{Command, Stdio}; use std::io::{Write}; -use log::{error, warn}; +use log::{error}; use std::path::Path; pub struct LinuxClipboardManager {} @@ -86,6 +86,10 @@ impl super::ClipboardManager for LinuxClipboardManager { let res = Command::new("xclip") .args(&["-selection", "clipboard", "-t", mime, "-i", &image_path]) .spawn(); + + if let Err(e) = res { + error!("Could not set image clipboard: {}", e); + } } } diff --git a/src/config/mod.rs b/src/config/mod.rs index 70f5645..d4d6589 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -427,12 +427,10 @@ impl ConfigSet { // Check if some triggers are conflicting with each other // For more information, see: https://github.com/federico-terzi/espanso/issues/135 if default.conflict_check { - for s in specific.iter() { - let has_conflicts = Self::has_conflicts(&default, &specific); - if has_conflicts { - eprintln!("Warning: some triggers had conflicts and may not behave as intended"); - eprintln!("To turn off this check, add \"conflict_check: false\" in the configuration"); - } + let has_conflicts = Self::has_conflicts(&default, &specific); + if has_conflicts { + eprintln!("Warning: some triggers had conflicts and may not behave as intended"); + eprintln!("To turn off this check, add \"conflict_check: false\" in the configuration"); } } @@ -583,8 +581,7 @@ mod tests { use super::*; use std::io::Write; use tempfile::{NamedTempFile, TempDir}; - use std::any::Any; - use crate::matcher::{TextContent, MatchContentType}; + use crate::matcher::{MatchContentType}; const TEST_WORKING_CONFIG_FILE : &str = include_str!("../res/test/working_config.yml"); const TEST_CONFIG_FILE_WITH_BAD_YAML : &str = include_str!("../res/test/config_with_bad_yaml.yml"); @@ -593,7 +590,7 @@ mod tests { fn create_tmp_file(string: &str) -> NamedTempFile { let file = NamedTempFile::new().unwrap(); - file.as_file().write_all(string.as_bytes()); + file.as_file().write_all(string.as_bytes()).unwrap(); file } @@ -716,7 +713,7 @@ mod tests { let package_dir = TempDir::new().expect("unable to create package directory"); let default_path = data_dir.path().join(DEFAULT_CONFIG_FILE_NAME); - fs::write(default_path, default_content); + fs::write(default_path, default_content).unwrap(); (data_dir, package_dir) } @@ -724,7 +721,7 @@ mod tests { pub fn create_temp_file_in_dir(tmp_dir: &PathBuf, name: &str, content: &str) -> PathBuf { let user_defined_path = tmp_dir.join(name); let user_defined_path_copy = user_defined_path.clone(); - fs::write(user_defined_path, content); + fs::write(user_defined_path, content).unwrap(); user_defined_path_copy } @@ -732,7 +729,7 @@ mod tests { pub fn create_user_config_file(tmp_dir: &Path, name: &str, content: &str) -> PathBuf { let user_config_dir = tmp_dir.join(USER_CONFIGS_FOLDER_NAME); if !user_config_dir.exists() { - create_dir_all(&user_config_dir); + create_dir_all(&user_config_dir).unwrap(); } create_temp_file_in_dir(&user_config_dir, name, content) @@ -741,7 +738,7 @@ mod tests { pub fn create_package_file(package_data_dir: &Path, package_name: &str, filename: &str, content: &str) -> PathBuf { let package_dir = package_data_dir.join(package_name); if !package_dir.exists() { - create_dir_all(&package_dir); + create_dir_all(&package_dir).unwrap(); } create_temp_file_in_dir(&package_dir, filename, content) @@ -824,11 +821,11 @@ mod tests { fn test_config_set_specific_file_duplicate_name() { let (data_dir, package_dir) = create_temp_espanso_directories(); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" name: specific1 "###); - let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" + create_user_config_file(data_dir.path(), "specific2.yml", r###" name: specific1 "###); @@ -847,7 +844,7 @@ mod tests { replace: "Bob" "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific1.yml", r###" + create_user_config_file(data_dir.path(), "specific1.yml", r###" name: specific1 matches: @@ -874,7 +871,7 @@ mod tests { replace: "Bob" "###); - let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" + create_user_config_file(data_dir.path(), "specific2.yml", r###" name: specific1 matches: @@ -906,7 +903,7 @@ mod tests { replace: "Bob" "###); - let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" + create_user_config_file(data_dir.path(), "specific2.yml", r###" name: specific1 exclude_default_entries: true @@ -941,7 +938,7 @@ mod tests { "### ); - let user_defined_path2 = create_user_config_file(data_dir.path(), "specific.zzz", r###" + create_user_config_file(data_dir.path(), "specific.zzz", r###" name: specific1 exclude_default_entries: true @@ -959,11 +956,11 @@ mod tests { fn test_config_set_no_parent_configs_works_correctly() { let (data_dir, package_dir) = create_temp_espanso_directories(); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" name: specific1 "###); - let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" + create_user_config_file(data_dir.path(), "specific2.yml", r###" name: specific2 "###); @@ -979,7 +976,7 @@ mod tests { replace: Hasta la vista "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" parent: default matches: @@ -1002,7 +999,7 @@ mod tests { replace: Hasta la vista "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" matches: - trigger: "hello" replace: "world" @@ -1024,7 +1021,7 @@ mod tests { replace: Hasta la vista "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" name: custom1 parent: default @@ -1033,7 +1030,7 @@ mod tests { replace: "world" "###); - let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" + create_user_config_file(data_dir.path(), "specific2.yml", r###" parent: custom1 matches: @@ -1057,7 +1054,7 @@ mod tests { replace: Hasta la vista "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" parent: default matches: @@ -1085,7 +1082,7 @@ mod tests { replace: Hasta la vista "###); - let package_path = create_package_file(package_dir.path(), "package1", "package.yml", r###" + create_package_file(package_dir.path(), "package1", "package.yml", r###" parent: default matches: @@ -1108,7 +1105,7 @@ mod tests { replace: Hasta la vista "###); - let package_path = create_package_file(package_dir.path(), "package1", "package.yml", r###" + create_package_file(package_dir.path(), "package1", "package.yml", r###" matches: - trigger: "harry" replace: "potter" @@ -1129,7 +1126,7 @@ mod tests { replace: Hasta la vista "###); - let package_path = create_package_file(package_dir.path(), "package1", "package.yml", r###" + create_package_file(package_dir.path(), "package1", "package.yml", r###" name: package1 matches: @@ -1137,7 +1134,7 @@ mod tests { replace: "potter" "###); - let package_path2 = create_package_file(package_dir.path(), "package1", "addon.yml", r###" + create_package_file(package_dir.path(), "package1", "addon.yml", r###" parent: package1 matches: @@ -1175,7 +1172,7 @@ mod tests { replace: Jon "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" name: specific1 matches: @@ -1199,7 +1196,7 @@ mod tests { replace: Error "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" name: specific1 matches: @@ -1221,7 +1218,7 @@ mod tests { replace: Jon "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" name: specific1 matches: @@ -1243,14 +1240,14 @@ mod tests { replace: Jon "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" name: specific1 matches: - trigger: "bad" replace: "Conflict" "###); - let user_defined_path2 = create_user_config_file(data_dir.path(), "specific2.yml", r###" + create_user_config_file(data_dir.path(), "specific2.yml", r###" name: specific2 matches: @@ -1272,7 +1269,7 @@ mod tests { format: "%m" "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" global_vars: - name: specificvar type: date @@ -1298,7 +1295,7 @@ mod tests { format: "%m" "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" parent: default global_vars: - name: specificvar @@ -1324,7 +1321,7 @@ mod tests { format: "%m" "###); - let user_defined_path = create_user_config_file(data_dir.path(), "specific.yml", r###" + create_user_config_file(data_dir.path(), "specific.yml", r###" exclude_default_entries: true global_vars: diff --git a/src/config/runtime.rs b/src/config/runtime.rs index 2e2aff0..6a07fac 100644 --- a/src/config/runtime.rs +++ b/src/config/runtime.rs @@ -204,12 +204,8 @@ impl <'a, S: SystemManager> super::ConfigManager<'a> for RuntimeConfigManager<'a #[cfg(test)] mod tests { use super::*; - use tempfile::{NamedTempFile, TempDir}; - use crate::config::{DEFAULT_CONFIG_FILE_NAME, DEFAULT_CONFIG_FILE_CONTENT}; - use std::fs; - use std::path::PathBuf; use crate::config::ConfigManager; - use crate::config::tests::{create_temp_espanso_directories, create_temp_file_in_dir, create_user_config_file}; + use crate::config::tests::{create_temp_espanso_directories, create_user_config_file}; struct DummySystemManager { title: RefCell, @@ -251,18 +247,18 @@ mod tests { fn test_runtime_constructor_regex_load_correctly() { let (data_dir, package_dir) = create_temp_espanso_directories(); - let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" + create_user_config_file(&data_dir.path(), "specific.yml", r###" name: myname1 filter_exec: "Title" "###); - let specific_path2 = create_user_config_file(&data_dir.path(), "specific2.yml", r###" + create_user_config_file(&data_dir.path(), "specific2.yml", r###" name: myname2 filter_title: "Yeah" filter_class: "Car" "###); - let specific_path3 = create_user_config_file(&data_dir.path(), "specific3.yml", r###" + create_user_config_file(&data_dir.path(), "specific3.yml", r###" name: myname3 filter_title: "Nice" "###); @@ -302,18 +298,18 @@ mod tests { fn test_runtime_constructor_malformed_regexes_are_ignored() { let (data_dir, package_dir) = create_temp_espanso_directories(); - let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" + create_user_config_file(&data_dir.path(), "specific.yml", r###" name: myname1 filter_exec: "[`-_]" "###); - let specific_path2 = create_user_config_file(&data_dir.path(), "specific2.yml", r###" + create_user_config_file(&data_dir.path(), "specific2.yml", r###" name: myname2 filter_title: "[`-_]" filter_class: "Car" "###); - let specific_path3 = create_user_config_file(&data_dir.path(), "specific3.yml", r###" + create_user_config_file(&data_dir.path(), "specific3.yml", r###" name: myname3 filter_title: "Nice" "###); @@ -353,7 +349,7 @@ mod tests { fn test_runtime_calculate_active_config_specific_title_match() { let (data_dir, package_dir) = create_temp_espanso_directories(); - let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" + create_user_config_file(&data_dir.path(), "specific.yml", r###" name: chrome filter_title: "Chrome" "###); @@ -368,10 +364,11 @@ mod tests { assert_eq!(config_manager.calculate_active_config().name, "chrome"); } + #[test] fn test_runtime_calculate_active_config_specific_class_match() { let (data_dir, package_dir) = create_temp_espanso_directories(); - let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" + create_user_config_file(&data_dir.path(), "specific.yml", r###" name: chrome filter_class: "Chrome" "###); @@ -386,10 +383,11 @@ mod tests { assert_eq!(config_manager.calculate_active_config().name, "chrome"); } + #[test] fn test_runtime_calculate_active_config_specific_exec_match() { let (data_dir, package_dir) = create_temp_espanso_directories(); - let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" + create_user_config_file(&data_dir.path(), "specific.yml", r###" name: chrome filter_exec: "chrome.exe" "###); @@ -404,10 +402,11 @@ mod tests { assert_eq!(config_manager.calculate_active_config().name, "chrome"); } + #[test] fn test_runtime_calculate_active_config_specific_multi_filter_match() { let (data_dir, package_dir) = create_temp_espanso_directories(); - let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" + create_user_config_file(&data_dir.path(), "specific.yml", r###" name: chrome filter_class: Browser filter_exec: "firefox.exe" @@ -427,7 +426,7 @@ mod tests { fn test_runtime_calculate_active_config_no_match() { let (data_dir, package_dir) = create_temp_espanso_directories(); - let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" + create_user_config_file(&data_dir.path(), "specific.yml", r###" name: firefox filter_title: "Firefox" "###); @@ -446,7 +445,7 @@ mod tests { fn test_runtime_active_config_cache() { let (data_dir, package_dir) = create_temp_espanso_directories(); - let specific_path = create_user_config_file(&data_dir.path(), "specific.yml", r###" + create_user_config_file(&data_dir.path(), "specific.yml", r###" name: firefox filter_title: "Firefox" "###); diff --git a/src/context/linux.rs b/src/context/linux.rs index 13b583d..2f8e0a6 100644 --- a/src/context/linux.rs +++ b/src/context/linux.rs @@ -23,9 +23,8 @@ use crate::event::*; use crate::event::KeyModifier::*; use crate::bridge::linux::*; use std::process::exit; -use log::{debug, error, info}; +use log::{debug, error}; use std::ffi::CStr; -use std::{thread, time}; use std::sync::atomic::AtomicBool; use std::sync::Arc; use std::sync::atomic::Ordering::Acquire; @@ -38,7 +37,7 @@ pub struct LinuxContext { } impl LinuxContext { - pub fn new(config: Configs, send_channel: Sender, is_injecting: Arc) -> Box { + pub fn new(_: Configs, send_channel: Sender, is_injecting: Arc) -> Box { // Check if the X11 context is available let x11_available = unsafe { check_x11() @@ -86,7 +85,7 @@ impl Drop for LinuxContext { // Native bridge code -extern fn keypress_callback(_self: *mut c_void, raw_buffer: *const u8, len: i32, +extern fn keypress_callback(_self: *mut c_void, raw_buffer: *const u8, _len: i32, event_type: i32, key_code: i32) { unsafe { let _self = _self as *mut LinuxContext; @@ -101,7 +100,7 @@ extern fn keypress_callback(_self: *mut c_void, raw_buffer: *const u8, len: i32, if event_type == 0 { // Char event // Convert the received buffer to a string - let c_str = CStr::from_ptr(raw_buffer as (*const c_char)); + let c_str = CStr::from_ptr(raw_buffer as *const c_char); let char_str = c_str.to_str(); // Send the char through the channel diff --git a/src/engine.rs b/src/engine.rs index f96e404..0527533 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -17,7 +17,7 @@ * along with espanso. If not, see . */ -use crate::matcher::{Match, MatchReceiver, MatchContentType}; +use crate::matcher::{Match, MatchReceiver}; use crate::keyboard::KeyboardManager; use crate::config::ConfigManager; use crate::config::BackendType; @@ -25,17 +25,13 @@ use crate::clipboard::ClipboardManager; use log::{info, warn, debug, error}; use crate::ui::{UIManager, MenuItem, MenuItemType}; use crate::event::{ActionEventReceiver, ActionType, SystemEventReceiver, SystemEvent}; -use crate::extension::Extension; use crate::render::{Renderer, RenderResult}; use std::cell::RefCell; use std::process::exit; -use std::collections::HashMap; -use std::path::PathBuf; -use regex::{Regex, Captures}; -use std::time::SystemTime; +use regex::{Regex}; use std::sync::Arc; use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering::{Relaxed, Release, Acquire, AcqRel, SeqCst}; +use std::sync::atomic::Ordering::Release; pub struct Engine<'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIManager, R: Renderer> { @@ -47,7 +43,6 @@ pub struct Engine<'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager< is_injecting: Arc, enabled: RefCell, - last_action_time: RefCell, // Used to block espanso from re-interpreting it's own inputs } impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIManager, R: Renderer> @@ -56,7 +51,6 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa config_manager: &'a M, ui_manager: &'a U, renderer: &'a R, is_injecting: Arc) -> Engine<'a, S, C, M, U, R> { let enabled = RefCell::new(true); - let last_action_time = RefCell::new(SystemTime::now()); Engine{keyboard_manager, clipboard_manager, @@ -65,7 +59,6 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa renderer, is_injecting, enabled, - last_action_time, } } @@ -111,20 +104,6 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa None } } - - /// Used to check if the last action has been executed within a specified interval. - /// If so, return true (blocking the action), otherwise false. - fn check_last_action_and_set(&self, interval: u128) -> bool { - let mut last_action_time = self.last_action_time.borrow_mut(); - if let Ok(elapsed) = last_action_time.elapsed() { - if elapsed.as_millis() < interval { - return true; - } - } - - (*last_action_time) = SystemTime::now(); - return false; - } } lazy_static! { diff --git a/src/event/mod.rs b/src/event/mod.rs index 2547bdf..53f901d 100644 --- a/src/event/mod.rs +++ b/src/event/mod.rs @@ -21,6 +21,7 @@ pub(crate) mod manager; use serde::{Serialize, Deserialize}; +#[allow(dead_code)] #[derive(Debug, Clone)] pub enum Event { Action(ActionType), @@ -58,7 +59,7 @@ pub enum KeyEvent { Other } -#[warn(non_camel_case_types)] +#[allow(non_camel_case_types)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum KeyModifier { CTRL, @@ -133,6 +134,7 @@ impl KeyModifier { } } +#[allow(dead_code)] #[derive(Debug, Clone)] pub enum SystemEvent { // MacOS specific diff --git a/src/extension/clipboard.rs b/src/extension/clipboard.rs index 778bbfe..c8442cd 100644 --- a/src/extension/clipboard.rs +++ b/src/extension/clipboard.rs @@ -17,7 +17,7 @@ * along with espanso. If not, see . */ -use serde_yaml::{Mapping, Value}; +use serde_yaml::{Mapping}; use crate::clipboard::ClipboardManager; pub struct ClipboardExtension { @@ -37,7 +37,7 @@ impl super::Extension for ClipboardExtension { String::from("clipboard") } - fn calculate(&self, params: &Mapping, _: &Vec) -> Option { + fn calculate(&self, _: &Mapping, _: &Vec) -> Option { self.clipboard_manager.get_clipboard() } } \ No newline at end of file diff --git a/src/keyboard/mod.rs b/src/keyboard/mod.rs index 045be16..718b42f 100644 --- a/src/keyboard/mod.rs +++ b/src/keyboard/mod.rs @@ -17,7 +17,7 @@ * along with espanso. If not, see . */ -use serde::{Serialize, Deserialize, Deserializer}; +use serde::{Serialize, Deserialize}; #[cfg(target_os = "windows")] mod windows; diff --git a/src/main.rs b/src/main.rs index 4e0f4a6..dc788fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,32 +20,32 @@ #[macro_use] extern crate lazy_static; -use std::thread; use std::fs::{File, OpenOptions}; +use std::io::{BufRead, BufReader}; use std::process::exit; -use std::sync::{mpsc, Arc}; +use std::sync::{Arc, mpsc}; +use std::sync::atomic::AtomicBool; use std::sync::mpsc::Receiver; +use std::thread; use std::time::Duration; -use clap::{App, Arg, SubCommand, ArgMatches}; +use clap::{App, Arg, ArgMatches, SubCommand}; use fs2::FileExt; -use log::{info, warn, LevelFilter}; +use log::{info, LevelFilter, warn}; use simplelog::{CombinedLogger, SharedLogger, TerminalMode, TermLogger, WriteLogger}; -use crate::config::{ConfigSet, ConfigManager}; +use crate::config::{ConfigManager, ConfigSet}; use crate::config::runtime::RuntimeConfigManager; use crate::engine::Engine; use crate::event::*; use crate::event::manager::{DefaultEventManager, EventManager}; use crate::matcher::scrolling::ScrollingMatcher; +use crate::package::{InstallResult, PackageManager, RemoveResult, UpdateResult}; +use crate::package::default::DefaultPackageManager; +use crate::package::zip::ZipPackageResolver; +use crate::protocol::*; use crate::system::SystemManager; use crate::ui::UIManager; -use crate::protocol::*; -use std::io::{BufReader, BufRead}; -use crate::package::default::DefaultPackageManager; -use crate::package::{PackageManager, InstallResult, UpdateResult, RemoveResult, PackageResolver}; -use std::sync::atomic::AtomicBool; -use crate::package::zip::ZipPackageResolver; mod ui; mod edit; @@ -445,7 +445,7 @@ fn start_daemon(config_set: ConfigSet) { // If Systemd is not available in the system, espanso should default to unmanaged mode // See issue https://github.com/federico-terzi/espanso/issues/139 - let force_unmanaged = if let Err(status) = status { + let force_unmanaged = if let Err(_) = status { true } else { false @@ -993,7 +993,7 @@ fn edit_main(matches: &ArgMatches) { if should_reload { // Load the configuration - let mut config_set = ConfigSet::load_default().unwrap_or_else(|e| { + let config_set = ConfigSet::load_default().unwrap_or_else(|e| { eprintln!("{}", e); eprintln!("Unable to reload espanso due to previous configuration error."); exit(1); diff --git a/src/matcher/mod.rs b/src/matcher/mod.rs index d1f88e8..5b68433 100644 --- a/src/matcher/mod.rs +++ b/src/matcher/mod.rs @@ -90,7 +90,7 @@ impl<'a> From<&'a AutoMatch> for Match{ if other.propagate_case { // List with first letter capitalized let first_capitalized : Vec = triggers.iter().map(|trigger| { - let mut capitalized = trigger.clone(); + let capitalized = trigger.clone(); let mut v: Vec = capitalized.chars().collect(); v[0] = v[0].to_uppercase().nth(0).unwrap(); v.into_iter().collect() diff --git a/src/matcher/scrolling.rs b/src/matcher/scrolling.rs index b1a24a8..6b43794 100644 --- a/src/matcher/scrolling.rs +++ b/src/matcher/scrolling.rs @@ -18,7 +18,7 @@ */ use crate::matcher::{Match, MatchReceiver, TriggerEntry}; -use std::cell::{RefCell, Ref}; +use std::cell::{RefCell}; use crate::event::{KeyModifier, ActionEventReceiver, ActionType}; use crate::config::ConfigManager; use crate::event::KeyModifier::BACKSPACE; diff --git a/src/package/default.rs b/src/package/default.rs index e2f3caf..ccf8d32 100644 --- a/src/package/default.rs +++ b/src/package/default.rs @@ -26,7 +26,6 @@ use std::time::{SystemTime, UNIX_EPOCH}; use crate::package::UpdateResult::{NotOutdated, Updated}; use crate::package::InstallResult::{NotFoundInIndex, AlreadyInstalled, BlockedExternalPackage}; use std::fs; -use tempfile::TempDir; use regex::Regex; use crate::package::RemoveResult::Removed; use std::collections::HashMap; @@ -335,7 +334,6 @@ mod tests { use crate::package::PackageManager; use std::fs::{create_dir, create_dir_all}; use crate::package::InstallResult::*; - use std::io::Write; use crate::package::zip::ZipPackageResolver; const OUTDATED_INDEX_CONTENT : &str = include_str!("../res/test/outdated_index.json"); @@ -370,7 +368,7 @@ mod tests { #[test] fn test_download_index() { - let temp = create_temp_package_manager(|_, _| {}); + create_temp_package_manager(|_, _| {}); let index = DefaultPackageManager::request_index(); assert!(index.is_ok()); @@ -381,7 +379,7 @@ mod tests { fn test_outdated_index() { let temp = create_temp_package_manager(|_, data_dir| { let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, OUTDATED_INDEX_CONTENT); + std::fs::write(index_file, OUTDATED_INDEX_CONTENT).unwrap(); }); assert!(temp.package_manager.is_index_outdated()); @@ -394,7 +392,7 @@ mod tests { let current_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards"); let current_timestamp = current_time.as_secs(); let new_contents = INDEX_CONTENT_WITHOUT_UPDATE.replace("XXXX", &format!("{}", current_timestamp)); - std::fs::write(index_file, new_contents); + std::fs::write(index_file, new_contents).unwrap(); }); assert_eq!(temp.package_manager.update_index(false).unwrap(), UpdateResult::NotOutdated); @@ -407,7 +405,7 @@ mod tests { let current_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards"); let current_timestamp = current_time.as_secs(); let new_contents = INDEX_CONTENT_WITHOUT_UPDATE.replace("XXXX", &format!("{}", current_timestamp)); - std::fs::write(index_file, new_contents); + std::fs::write(index_file, new_contents).unwrap(); }); assert_eq!(temp.package_manager.update_index(true).unwrap(), UpdateResult::Updated); @@ -417,7 +415,7 @@ mod tests { fn test_outdated_index_should_be_updated() { let mut temp = create_temp_package_manager(|_, data_dir| { let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, OUTDATED_INDEX_CONTENT); + std::fs::write(index_file, OUTDATED_INDEX_CONTENT).unwrap(); }); assert_eq!(temp.package_manager.update_index(false).unwrap(), UpdateResult::Updated); @@ -433,9 +431,9 @@ mod tests { #[test] fn test_get_package_should_be_found() { - let mut temp = create_temp_package_manager(|_, data_dir| { + let temp = create_temp_package_manager(|_, data_dir| { let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, GET_PACKAGE_INDEX); + std::fs::write(index_file, GET_PACKAGE_INDEX).unwrap(); }); assert_eq!(temp.package_manager.get_package("italian-accents").unwrap().title, "Italian Accents"); @@ -443,9 +441,9 @@ mod tests { #[test] fn test_get_package_should_not_be_found() { - let mut temp = create_temp_package_manager(|_, data_dir| { + let temp = create_temp_package_manager(|_, data_dir| { let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, GET_PACKAGE_INDEX); + std::fs::write(index_file, GET_PACKAGE_INDEX).unwrap(); }); assert!(temp.package_manager.get_package("not-existing").is_none()); @@ -453,10 +451,10 @@ mod tests { #[test] fn test_list_local_packages_names() { - let mut temp = create_temp_package_manager(|package_dir, _| { - create_dir(package_dir.join("package-1")); - create_dir(package_dir.join("package2")); - std::fs::write(package_dir.join("dummyfile.txt"), "test"); + let temp = create_temp_package_manager(|package_dir, _| { + create_dir(package_dir.join("package-1")).unwrap(); + create_dir(package_dir.join("package2")).unwrap(); + std::fs::write(package_dir.join("dummyfile.txt"), "test").unwrap(); }); let packages = temp.package_manager.list_local_packages_names(); @@ -467,9 +465,9 @@ mod tests { #[test] fn test_install_package_not_found() { - let mut temp = create_temp_package_manager(|package_dir, data_dir| { + let temp = create_temp_package_manager(|_, data_dir| { let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, INSTALL_PACKAGE_INDEX); + std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap(); }); assert_eq!(temp.package_manager.install_package("doesnotexist", false).unwrap(), NotFoundInIndex); @@ -477,10 +475,10 @@ mod tests { #[test] fn test_install_package_already_installed() { - let mut temp = create_temp_package_manager(|package_dir, data_dir| { - create_dir(package_dir.join("italian-accents")); + let temp = create_temp_package_manager(|package_dir, data_dir| { + create_dir(package_dir.join("italian-accents")).unwrap(); let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, INSTALL_PACKAGE_INDEX); + std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap(); }); assert_eq!(temp.package_manager.install_package("italian-accents", false).unwrap(), AlreadyInstalled); @@ -488,9 +486,9 @@ mod tests { #[test] fn test_install_package() { - let mut temp = create_temp_package_manager(|_, data_dir| { + let temp = create_temp_package_manager(|_, data_dir| { let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, INSTALL_PACKAGE_INDEX); + std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap(); }); assert_eq!(temp.package_manager.install_package("dummy-package", false).unwrap(), Installed); @@ -501,9 +499,9 @@ mod tests { #[test] fn test_install_package_does_not_exist_in_repo() { - let mut temp = create_temp_package_manager(|_, data_dir| { + let temp = create_temp_package_manager(|_, data_dir| { let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, INSTALL_PACKAGE_INDEX); + std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap(); }); assert_eq!(temp.package_manager.install_package("not-existing", false).unwrap(), NotFoundInRepo); @@ -511,9 +509,9 @@ mod tests { #[test] fn test_install_package_missing_version() { - let mut temp = create_temp_package_manager(|_, data_dir| { + let temp = create_temp_package_manager(|_, data_dir| { let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, INSTALL_PACKAGE_INDEX); + std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap(); }); assert_eq!(temp.package_manager.install_package("dummy-package2", false).unwrap(), MissingPackageVersion); @@ -521,9 +519,9 @@ mod tests { #[test] fn test_install_package_missing_readme_unable_to_parse_package_info() { - let mut temp = create_temp_package_manager(|_, data_dir| { + let temp = create_temp_package_manager(|_, data_dir| { let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, INSTALL_PACKAGE_INDEX); + std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap(); }); assert_eq!(temp.package_manager.install_package("dummy-package3", false).unwrap(), UnableToParsePackageInfo); @@ -531,9 +529,9 @@ mod tests { #[test] fn test_install_package_bad_readme_unable_to_parse_package_info() { - let mut temp = create_temp_package_manager(|_, data_dir| { + let temp = create_temp_package_manager(|_, data_dir| { let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, INSTALL_PACKAGE_INDEX); + std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap(); }); assert_eq!(temp.package_manager.install_package("dummy-package4", false).unwrap(), UnableToParsePackageInfo); @@ -541,9 +539,9 @@ mod tests { #[test] fn test_list_local_packages() { - let mut temp = create_temp_package_manager(|_, data_dir| { + let temp = create_temp_package_manager(|_, data_dir| { let index_file = data_dir.join(DEFAULT_PACKAGE_INDEX_FILE); - std::fs::write(index_file, INSTALL_PACKAGE_INDEX); + std::fs::write(index_file, INSTALL_PACKAGE_INDEX).unwrap(); }); assert_eq!(temp.package_manager.install_package("dummy-package", false).unwrap(), Installed); @@ -558,11 +556,11 @@ mod tests { #[test] fn test_remove_package() { - let mut temp = create_temp_package_manager(|package_dir, _| { + let temp = create_temp_package_manager(|package_dir, _| { let dummy_package_dir = package_dir.join("dummy-package"); - create_dir_all(&dummy_package_dir); - std::fs::write(dummy_package_dir.join("README.md"), "readme"); - std::fs::write(dummy_package_dir.join("package.yml"), "name: package"); + create_dir_all(&dummy_package_dir).unwrap(); + std::fs::write(dummy_package_dir.join("README.md"), "readme").unwrap(); + std::fs::write(dummy_package_dir.join("package.yml"), "name: package").unwrap(); }); assert!(temp.package_dir.path().join("dummy-package").exists()); @@ -576,7 +574,7 @@ mod tests { #[test] fn test_remove_package_not_found() { - let mut temp = create_temp_package_manager(|_, _| {}); + let temp = create_temp_package_manager(|_, _| {}); assert_eq!(temp.package_manager.remove_package("not-existing").unwrap(), RemoveResult::NotFound); } @@ -594,7 +592,7 @@ mod tests { package_repo: "https://github.com/federico-terzi/espanso-hub-core" is_core: true --- - "###); + "###).unwrap(); let package = DefaultPackageManager::parse_package_from_readme(file.path()).unwrap(); @@ -626,7 +624,7 @@ mod tests { is_core: true --- Readme text - "###); + "###).unwrap(); let package = DefaultPackageManager::parse_package_from_readme(file.path()).unwrap(); diff --git a/src/package/zip.rs b/src/package/zip.rs index 169e78d..e12b26d 100644 --- a/src/package/zip.rs +++ b/src/package/zip.rs @@ -1,9 +1,7 @@ use tempfile::TempDir; use std::error::Error; -use super::PackageResolver; -use std::io::{Cursor, copy, Read}; +use std::io::{Cursor, copy}; use std::{fs, io}; -use std::fs::File; use log::debug; pub struct ZipPackageResolver; @@ -33,7 +31,7 @@ impl super::PackageResolver for ZipPackageResolver { // Find the root folder name let mut root_folder = { - let mut root_folder = archive.by_index(0).unwrap(); + let root_folder = archive.by_index(0).unwrap(); let root_folder = root_folder.sanitized_name(); root_folder.to_str().unwrap().to_owned() }; @@ -77,7 +75,7 @@ impl super::PackageResolver for ZipPackageResolver { #[cfg(test)] mod tests { use super::*; - use tempfile::{TempDir, NamedTempFile}; + use super::super::PackageResolver; #[test] fn test_clone_temp_repository() { diff --git a/src/render/default.rs b/src/render/default.rs index dca2c70..a9da347 100644 --- a/src/render/default.rs +++ b/src/render/default.rs @@ -17,8 +17,7 @@ * along with espanso. If not, see . */ -use serde_yaml::{Mapping, Value}; -use std::path::PathBuf; +use serde_yaml::{Value}; use std::collections::HashMap; use regex::{Regex, Captures}; use log::{warn, error}; @@ -50,7 +49,7 @@ impl DefaultRenderer { // Compile the regexes let passive_match_regex = Regex::new(&config.passive_match_regex) .unwrap_or_else(|e| { - panic!("Invalid passive match regex"); + panic!("Invalid passive match regex: {:?}", e); }); DefaultRenderer{ diff --git a/src/sysdaemon.rs b/src/sysdaemon.rs index 4bbf06c..706af9d 100644 --- a/src/sysdaemon.rs +++ b/src/sysdaemon.rs @@ -108,9 +108,9 @@ const LINUX_SERVICE_CONTENT : &str = include_str!("res/linux/systemd.service"); const LINUX_SERVICE_FILENAME : &str = "espanso.service"; #[cfg(target_os = "linux")] -pub fn register(config_set: ConfigSet) { +pub fn register(_: ConfigSet) { use std::fs::create_dir_all; - use std::process::{Command, ExitStatus}; + use std::process::{Command}; // Check if espanso service is already registered let res = Command::new("systemctl") @@ -191,7 +191,7 @@ pub enum VerifyResult { #[cfg(target_os = "linux")] pub fn verify() -> VerifyResult { use regex::Regex; - use std::process::{Command, ExitStatus}; + use std::process::{Command}; // Check if espanso service is already registered let res = Command::new("systemctl") @@ -206,7 +206,7 @@ pub fn verify() -> VerifyResult { } lazy_static! { - static ref ExecPathRegex: Regex = Regex::new("ExecStart=(?P.*?)\\s").unwrap(); + static ref EXEC_PATH_REGEX: Regex = Regex::new("ExecStart=(?P.*?)\\s").unwrap(); } // Check if the currently registered path is valid @@ -217,7 +217,7 @@ pub fn verify() -> VerifyResult { let output = String::from_utf8_lossy(res.stdout.as_slice()); let output = output.trim(); if res.status.success() { - let caps = ExecPathRegex.captures(output).unwrap(); + let caps = EXEC_PATH_REGEX.captures(output).unwrap(); let path = caps.get(1).map_or("", |m| m.as_str()); let espanso_path = std::env::current_exe().expect("Could not get espanso executable path"); @@ -231,13 +231,13 @@ pub fn verify() -> VerifyResult { } #[cfg(target_os = "linux")] -pub fn unregister(config_set: ConfigSet) { - use std::process::{Command, ExitStatus}; +pub fn unregister(_: ConfigSet) { + use std::process::{Command}; // Disable the service first - let res = Command::new("systemctl") + Command::new("systemctl") .args(&["--user", "disable", "espanso"]) - .status(); + .status().expect("Unable to invoke systemctl"); // Then delete the espanso.service entry let config_dir = dirs::config_dir().expect("Could not get configuration directory"); diff --git a/src/utils.rs b/src/utils.rs index ffd9106..259dc80 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -51,14 +51,14 @@ mod tests { let dest_tmp_dir = TempDir::new().expect("Error creating temp directory"); let source_dir = source_tmp_dir.path().join("source"); - create_dir(&source_dir); - std::fs::write(source_dir.join("file1.txt"), "file1"); - std::fs::write(source_dir.join("file2.txt"), "file2"); + create_dir(&source_dir).unwrap(); + std::fs::write(source_dir.join("file1.txt"), "file1").unwrap(); + std::fs::write(source_dir.join("file2.txt"), "file2").unwrap(); let target_dir = dest_tmp_dir.path().join("source"); - create_dir(&target_dir); + create_dir(&target_dir).unwrap(); - copy_dir(&source_dir, &target_dir); + copy_dir(&source_dir, &target_dir).unwrap(); assert!(dest_tmp_dir.path().join("source").exists()); assert!(dest_tmp_dir.path().join("source/file1.txt").exists()); @@ -71,17 +71,17 @@ mod tests { let dest_tmp_dir = TempDir::new().expect("Error creating temp directory"); let source_dir = source_tmp_dir.path().join("source"); - create_dir(&source_dir); - std::fs::write(source_dir.join("file1.txt"), "file1"); - std::fs::write(source_dir.join("file2.txt"), "file2"); + create_dir(&source_dir).unwrap(); + std::fs::write(source_dir.join("file1.txt"), "file1").unwrap(); + std::fs::write(source_dir.join("file2.txt"), "file2").unwrap(); let nested_dir = source_dir.join("nested"); - create_dir(&nested_dir); - std::fs::write(nested_dir.join("nestedfile.txt"), "nestedfile1"); + create_dir(&nested_dir).unwrap(); + std::fs::write(nested_dir.join("nestedfile.txt"), "nestedfile1").unwrap(); let target_dir = dest_tmp_dir.path().join("source"); - create_dir(&target_dir); + create_dir(&target_dir).unwrap(); - copy_dir(&source_dir, &target_dir); + copy_dir(&source_dir, &target_dir).unwrap(); assert!(dest_tmp_dir.path().join("source").exists()); assert!(dest_tmp_dir.path().join("source/file1.txt").exists());