ignore vim temp files

This commit is contained in:
Brandon Thomas committed 2023-03-23 00:43:01 -04:00
1 parent 168a476b72
commit 8bbc490b61
2 files changed
+42 -4

No files matched your search

@@ -9,6 +9,9 @@ pub fn load_ip_ban_list_from_directory<P: AsRef<Path>>(path: P) -> AnyhowResult<
for entry in paths {
let path = entry?.path();
if ignore_path(&path) {
continue;
}
let path_name = path.to_string_lossy().to_string();
let ip_set = load_ip_set_from_file(path)?;
if ip_set.is_empty() {
@@ -20,10 +23,16 @@ pub fn load_ip_ban_list_from_directory<P: AsRef<Path>>(path: P) -> AnyhowResult<
Ok(ip_ban_list)
}
fn ignore_path(path: &Path) -> bool {
// NB: Path is quoted for some reason and fails ends_with() etc., so we convert it to a string.
let test_path = path.to_string_lossy();
test_path.ends_with("~")
}
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use crate::middleware::ip_filter::ip_ban_list::load_ip_ban_list_from_directory::load_ip_ban_list_from_directory;
use std::path::{Path, PathBuf};
use crate::middleware::ip_filter::ip_ban_list::load_ip_ban_list_from_directory::{ignore_path, load_ip_ban_list_from_directory};
fn test_file(path_from_repo_root: &str) -> PathBuf {
// https://doc.rust-lang.org/cargo/reference/environment-variables.html
@@ -32,6 +41,16 @@ mod tests {
path
}
#[test]
fn test_ignore_paths() {
// Good
assert_eq!(false, ignore_path(Path::new("file.txt")));
assert_eq!(false, ignore_path(Path::new("file")));
// Vim files, private files, etc.
assert_eq!(true, ignore_path(Path::new("file.txt~")));
}
#[test]
fn test_load_ip_ban_list_from_directory() {
let directory = test_file("test_data/text_files/ip_ban_example/");
@@ -9,6 +9,9 @@ pub fn load_user_token_ban_list_from_directory<P: AsRef<Path>>(path: P) -> Anyho
for entry in paths {
let path = entry?.path();
if ignore_path(&path) {
continue;
}
let path_name = path.to_string_lossy().to_string();
let user_token_set = load_user_token_set_from_file(path)?;
if user_token_set.is_empty() {
@@ -20,10 +23,16 @@ pub fn load_user_token_ban_list_from_directory<P: AsRef<Path>>(path: P) -> Anyho
Ok(user_token_ban_list)
}
fn ignore_path(path: &Path) -> bool {
// NB: Path is quoted for some reason and fails ends_with() etc., so we convert it to a string.
let test_path = path.to_string_lossy();
test_path.ends_with("~")
}
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use crate::util::troll_user_bans::load_troll_user_ban_list_from_directory::load_user_token_ban_list_from_directory;
use std::path::{Path, PathBuf};
use crate::util::troll_user_bans::load_troll_user_ban_list_from_directory::{ignore_path, load_user_token_ban_list_from_directory};
fn test_file(path_from_repo_root: &str) -> PathBuf {
// https://doc.rust-lang.org/cargo/reference/environment-variables.html
@@ -32,6 +41,16 @@ mod tests {
path
}
#[test]
fn test_ignore_paths() {
// Good
assert_eq!(false, ignore_path(Path::new("file.txt")));
assert_eq!(false, ignore_path(Path::new("file")));
// Vim files, private files, etc.
assert_eq!(true, ignore_path(Path::new("file.txt~")));
}
#[test]
fn test_load_user_token_ban_list_from_directory() {
let directory = test_file("test_data/text_files/troll_user_token_ban_example/");