Run formatter
This commit is contained in:
parent
10fac30c7b
commit
a3c5bd7201
14
src/cli.rs
14
src/cli.rs
|
@ -14,8 +14,8 @@
|
||||||
//! .unwrap();
|
//! .unwrap();
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use clap::{App, Arg, Error};
|
|
||||||
use crate::error;
|
use crate::error;
|
||||||
|
use clap::{App, Arg, Error};
|
||||||
use std::{
|
use std::{
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
path::{PathBuf, MAIN_SEPARATOR},
|
path::{PathBuf, MAIN_SEPARATOR},
|
||||||
|
@ -216,11 +216,13 @@ where
|
||||||
|
|
||||||
if let Some(extensions) = args.values_of("extensions") {
|
if let Some(extensions) = args.values_of("extensions") {
|
||||||
for exts in extensions {
|
for exts in extensions {
|
||||||
filters.extend(
|
filters.extend(exts.split(',').filter_map(|ext| {
|
||||||
exts.split(',')
|
if ext.is_empty() {
|
||||||
.filter_map(|ext| if ext.is_empty() { None } else {
|
None
|
||||||
Some(format!("*.{}", ext.replace(".", ""))) }),
|
} else {
|
||||||
);
|
Some(format!("*.{}", ext.replace(".", "")))
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,9 +55,10 @@ impl<'a, T> From<PoisonError<T>> for Error {
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let (error_type, error) = match self {
|
let (error_type, error) = match self {
|
||||||
Self::Canonicalization(path, err) => {
|
Self::Canonicalization(path, err) => (
|
||||||
("Path", format!("couldn't canonicalize '{}':\n{}", path, err))
|
"Path",
|
||||||
}
|
format!("couldn't canonicalize '{}':\n{}", path, err),
|
||||||
|
),
|
||||||
Self::Clap(err) => ("Argument", err.to_string()),
|
Self::Clap(err) => ("Argument", err.to_string()),
|
||||||
Self::Glob(err) => ("Globset", err.to_string()),
|
Self::Glob(err) => ("Globset", err.to_string()),
|
||||||
Self::Io(err) => ("I/O", err.to_string()),
|
Self::Io(err) => ("I/O", err.to_string()),
|
||||||
|
|
|
@ -55,9 +55,9 @@ pub fn load(paths: &[PathBuf]) -> Gitignore {
|
||||||
let gitignore_path = p.join(".gitignore");
|
let gitignore_path = p.join(".gitignore");
|
||||||
if gitignore_path.exists() {
|
if gitignore_path.exists() {
|
||||||
if let Ok(f) = GitignoreFile::new(&gitignore_path) {
|
if let Ok(f) = GitignoreFile::new(&gitignore_path) {
|
||||||
debug!("Loaded {:?}", gitignore_path);
|
debug!("Loaded {:?}", gitignore_path);
|
||||||
files.push(f);
|
files.push(f);
|
||||||
} else {
|
} else {
|
||||||
debug!("Unable to load {:?}", gitignore_path);
|
debug!("Unable to load {:?}", gitignore_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,8 @@ pub fn load(paths: &[PathBuf]) -> Gitignore {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gitignore {
|
impl Gitignore {
|
||||||
const fn new(files: Vec<GitignoreFile>) -> Self{
|
const fn new(files: Vec<GitignoreFile>) -> Self {
|
||||||
Self{ files }
|
Self { files }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_excluded(&self, path: &Path) -> bool {
|
pub fn is_excluded(&self, path: &Path) -> bool {
|
||||||
|
@ -143,7 +143,7 @@ impl GitignoreFile {
|
||||||
patterns.push(p);
|
patterns.push(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self{
|
Ok(Self {
|
||||||
set: builder.build()?,
|
set: builder.build()?,
|
||||||
patterns,
|
patterns,
|
||||||
root: root.to_owned(),
|
root: root.to_owned(),
|
||||||
|
@ -181,14 +181,19 @@ impl GitignoreFile {
|
||||||
fn parse(contents: &[&str]) -> Vec<Pattern> {
|
fn parse(contents: &[&str]) -> Vec<Pattern> {
|
||||||
contents
|
contents
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|l| if !l.is_empty() && !l.starts_with('#') {
|
.filter_map(|l| {
|
||||||
Some(Pattern::parse(l)) } else { None })
|
if !l.is_empty() && !l.starts_with('#') {
|
||||||
|
Some(Pattern::parse(l))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pattern {
|
impl Pattern {
|
||||||
fn parse(pattern: &str) -> Self{
|
fn parse(pattern: &str) -> Self {
|
||||||
let mut normalized = String::from(pattern);
|
let mut normalized = String::from(pattern);
|
||||||
|
|
||||||
let pattern_type = if normalized.starts_with('!') {
|
let pattern_type = if normalized.starts_with('!') {
|
||||||
|
@ -213,7 +218,7 @@ impl Pattern {
|
||||||
normalized.remove(0);
|
normalized.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Self{
|
Self {
|
||||||
pattern: normalized,
|
pattern: normalized,
|
||||||
pattern_type,
|
pattern_type,
|
||||||
anchored,
|
anchored,
|
||||||
|
@ -222,13 +227,13 @@ impl Pattern {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<globset::Error> for Error {
|
impl From<globset::Error> for Error {
|
||||||
fn from(error: globset::Error) -> Self{
|
fn from(error: globset::Error) -> Self {
|
||||||
Self::GlobSet(error)
|
Self::GlobSet(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<io::Error> for Error {
|
impl From<io::Error> for Error {
|
||||||
fn from(error: io::Error) -> Self{
|
fn from(error: io::Error) -> Self {
|
||||||
Self::Io(error)
|
Self::Io(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,10 +55,10 @@ pub fn load(paths: &[PathBuf]) -> Ignore {
|
||||||
let ignore_path = p.join(".ignore");
|
let ignore_path = p.join(".ignore");
|
||||||
if ignore_path.exists() {
|
if ignore_path.exists() {
|
||||||
if let Ok(f) = IgnoreFile::new(&ignore_path) {
|
if let Ok(f) = IgnoreFile::new(&ignore_path) {
|
||||||
debug!("Loaded {:?}", ignore_path);
|
debug!("Loaded {:?}", ignore_path);
|
||||||
files.push(f);
|
files.push(f);
|
||||||
} else {
|
} else {
|
||||||
debug!("Unable to load {:?}", ignore_path);
|
debug!("Unable to load {:?}", ignore_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,13 @@ impl IgnoreFile {
|
||||||
fn parse(contents: &[&str]) -> Vec<Pattern> {
|
fn parse(contents: &[&str]) -> Vec<Pattern> {
|
||||||
contents
|
contents
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|l| if !l.is_empty() && !l.starts_with('#') { Some(Pattern::parse(l)) } else { None })
|
.filter_map(|l| {
|
||||||
|
if !l.is_empty() && !l.starts_with('#') {
|
||||||
|
Some(Pattern::parse(l))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::error;
|
use crate::error;
|
||||||
use crate::gitignore::Gitignore;
|
use crate::gitignore::Gitignore;
|
||||||
use globset::{Glob, GlobSet, GlobSetBuilder};
|
|
||||||
use crate::ignore::Ignore;
|
use crate::ignore::Ignore;
|
||||||
|
use globset::{Glob, GlobSet, GlobSetBuilder};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub struct NotificationFilter {
|
pub struct NotificationFilter {
|
||||||
|
|
|
@ -59,10 +59,10 @@ fn wrap_commands(cmd: &Vec<String>) -> Vec<String> {
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
mod imp {
|
mod imp {
|
||||||
//use super::wrap_commands;
|
//use super::wrap_commands;
|
||||||
use nix::libc::*;
|
|
||||||
use nix::{self, Error};
|
|
||||||
use crate::pathop::PathOp;
|
use crate::pathop::PathOp;
|
||||||
use crate::signal::Signal;
|
use crate::signal::Signal;
|
||||||
|
use nix::libc::*;
|
||||||
|
use nix::{self, Error};
|
||||||
use std::io::{self, Result};
|
use std::io::{self, Result};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::sync::*;
|
use std::sync::*;
|
||||||
|
@ -85,8 +85,8 @@ mod imp {
|
||||||
impl Process {
|
impl Process {
|
||||||
pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result<Self> {
|
pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result<Self> {
|
||||||
use nix::unistd::*;
|
use nix::unistd::*;
|
||||||
|
use std::convert::TryInto;
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
use std::convert::TryInto;
|
|
||||||
|
|
||||||
// Assemble command to run.
|
// Assemble command to run.
|
||||||
// This is either the first argument from cmd (if no_shell was given) or "sh".
|
// This is either the first argument from cmd (if no_shell was given) or "sh".
|
||||||
|
@ -112,16 +112,16 @@ mod imp {
|
||||||
command.env(name, val);
|
command.env(name, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe { command.pre_exec(|| setsid().map_err(from_nix_error).map(|_| ())); }
|
unsafe {
|
||||||
command
|
command.pre_exec(|| setsid().map_err(from_nix_error).map(|_| ()));
|
||||||
.spawn()
|
}
|
||||||
.and_then(|p| {
|
command.spawn().and_then(|p| {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
pgid: p.id().try_into().unwrap(),
|
pgid: p.id().try_into().unwrap(),
|
||||||
lock: Mutex::new(false),
|
lock: Mutex::new(false),
|
||||||
cvar: Condvar::new(),
|
cvar: Condvar::new(),
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reap(&self) {
|
pub fn reap(&self) {
|
||||||
|
@ -131,8 +131,7 @@ mod imp {
|
||||||
let mut finished = true;
|
let mut finished = true;
|
||||||
loop {
|
loop {
|
||||||
match waitpid(Pid::from_raw(-self.pgid), Some(WaitPidFlag::WNOHANG)) {
|
match waitpid(Pid::from_raw(-self.pgid), Some(WaitPidFlag::WNOHANG)) {
|
||||||
Ok(WaitStatus::Exited(_, _)) | Ok(WaitStatus::Signaled(_, _, _)) => {
|
Ok(WaitStatus::Exited(_, _)) | Ok(WaitStatus::Signaled(_, _, _)) => {}
|
||||||
}
|
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
finished = false;
|
finished = false;
|
||||||
break;
|
break;
|
||||||
|
@ -178,9 +177,9 @@ mod imp {
|
||||||
#[cfg(target_family = "windows")]
|
#[cfg(target_family = "windows")]
|
||||||
mod imp {
|
mod imp {
|
||||||
//use super::wrap_commands;
|
//use super::wrap_commands;
|
||||||
use kernel32::*;
|
|
||||||
use crate::pathop::PathOp;
|
use crate::pathop::PathOp;
|
||||||
use crate::signal::Signal;
|
use crate::signal::Signal;
|
||||||
|
use kernel32::*;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Result;
|
use std::io::Result;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
|
@ -6,6 +6,7 @@ use crate::notification_filter::NotificationFilter;
|
||||||
use crate::pathop::PathOp;
|
use crate::pathop::PathOp;
|
||||||
use crate::process::{self, Process};
|
use crate::process::{self, Process};
|
||||||
use crate::signal::{self, Signal};
|
use crate::signal::{self, Signal};
|
||||||
|
use crate::watcher::{Event, Watcher};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fs::canonicalize,
|
fs::canonicalize,
|
||||||
|
@ -16,7 +17,6 @@ use std::{
|
||||||
},
|
},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use crate::watcher::{Event, Watcher};
|
|
||||||
|
|
||||||
fn init_logger(debug: bool) {
|
fn init_logger(debug: bool) {
|
||||||
let mut log_builder = env_logger::Builder::new();
|
let mut log_builder = env_logger::Builder::new();
|
||||||
|
|
|
@ -100,7 +100,7 @@ where
|
||||||
|
|
||||||
set_handler(handler);
|
set_handler(handler);
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe {
|
unsafe {
|
||||||
let _ = sigaction(
|
let _ = sigaction(
|
||||||
SIGCHLD,
|
SIGCHLD,
|
||||||
|
@ -126,7 +126,7 @@ where
|
||||||
let default_action =
|
let default_action =
|
||||||
SigAction::new(SigHandler::SigDfl, SaFlags::empty(), SigSet::empty());
|
SigAction::new(SigHandler::SigDfl, SaFlags::empty(), SigSet::empty());
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe {
|
unsafe {
|
||||||
let _ = sigaction(signal, &default_action);
|
let _ = sigaction(signal, &default_action);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue