<commit_before>// ZSnapMgr :: ZFS snapshot and backup manager
//
// Copyright (c) 2016 by <NAME>
//

#![allow(unknown_lints)] // for Clippy

use std::env;
use std::ffi::{OsStr, OsString};
use std::fs;
use std::iter::Iterator;
use std::io;
use std::io::{Read, Write};
use std::ops::Deref;
use std::path::Path;
use std::process;

extern crate regex;
use regex::Regex;

extern crate termios;
use termios::*;

extern crate zsnapmgr;
use zsnapmgr::ZSnapMgr;

mod table;
use table::Table;

mod backups;
use backups::{Backup, Backups};

static USE_SUDO: bool = true;

// Print and flush.
macro_rules! printf {
    ( $fmt:expr ) => {
        print!($fmt);
        io::stdout().flush().unwrap();
    };
    ( $fmt:expr, $($arg:tt)* ) => {
        print!($fmt, $($arg)*);
        io::stdout().flush().unwrap();
    }
}

trait OptionDeref<T: Deref> {
    fn as_deref(&self) -> Option<&T::Target>;
}

impl<T: Deref> OptionDeref<T> for Option<T> {
    fn as_deref(&self) -> Option<&T::Target> {
        self.as_ref().map(Deref::deref)
    }
}

trait VecDeref<T: Deref> {
    fn as_deref(&self) -> Vec<&T::Target>;
}

impl<T: Deref> VecDeref<T> for Vec<T> {
    fn as_deref(&self) -> Vec<&T::Target> {
        self.iter().map(Deref::deref).collect()
    }
}

fn enumerate_files(path: &Path) -> Result<Box<dyn Iterator<Item = String>>, io::Error> {
    let readdir = fs::read_dir(path)?;
    let iter = readdir.filter_map(|entry_result| {
        match entry_result {
            Ok(entry) => {
                match entry.file_type() {
                    Ok(ft) => {
                        if ft.is_file() {
                            let path = entry.path();
                            let filename: &OsStr = path.file_name().unwrap();
                            match filename.to_str() {
                                Some(s) => Some(s.to_owned()),
                                None => {
                                    println!("error: filename {:?} is invalid UTF-8!", filename);
                                    None
                                }
                            }
                        } else {<commit_msg>allow symlinks when looking for previous backups<commit_after>// ZSnapMgr :: ZFS snapshot and backup manager
//
// Copyright (c) 2016 by <NAME>
//

#![allow(unknown_lints)] // for Clippy

use std::env;
use std::ffi::{OsStr, OsString};
use std::fs;
use std::iter::Iterator;
use std::io;
use std::io::{Read, Write};
use std::ops::Deref;
use std::path::Path;
use std::process;

extern crate regex;
use regex::Regex;

extern crate termios;
use termios::*;

extern crate zsnapmgr;
use zsnapmgr::ZSnapMgr;

mod table;
use table::Table;

mod backups;
use backups::{Backup, Backups};

static USE_SUDO: bool = true;

// Print and flush.
macro_rules! printf {
    ( $fmt:expr ) => {
        print!($fmt);
        io::stdout().flush().unwrap();
    };
    ( $fmt:expr, $($arg:tt)* ) => {
        print!($fmt, $($arg)*);
        io::stdout().flush().unwrap();
    }
}

trait OptionDeref<T: Deref> {
    fn as_deref(&self) -> Option<&T::Target>;
}

impl<T: Deref> OptionDeref<T> for Option<T> {
    fn as_deref(&self) -> Option<&T::Target> {
        self.as_ref().map(Deref::deref)
    }
}

trait VecDeref<T: Deref> {
    fn as_deref(&self) -> Vec<&T::Target>;
}

impl<T: Deref> VecDeref<T> for Vec<T> {
    fn as_deref(&self) -> Vec<&T::Target> {
        self.iter().map(Deref::deref).collect()
    }
}

fn enumerate_files(path: &Path) -> Result<Box<dyn Iterator<Item = String>>, io::Error> {
    let readdir = fs::read_dir(path)?;
    let iter = readdir.filter_map(|entry_result| {
        match entry_result {
            Ok(entry) => {
                match entry.file_type() {
                    Ok(ft) => {
                        if ft.is_file() || ft.is_symlink() {
                            let path = entry.path();
                            let filename: &OsStr = path.file_name().unwrap();
                            match filename.to_str() {
                                Some(s) => Some(s.to_owned()),
                                None => {
                                    println!("error: filename {:?} is invalid UTF-8!", filename);
                                    None
                                }
                            }
                        } else {
{'fraction_non_alphanumeric': 0.16550925925925927, 'fraction_numerical': 0.0023148148148148147, 'mean_word_length': 1.9195945945945947, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3974470', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1417, 'n_words': 301}