Skip to content

Commit

Permalink
crate: replace log with tracing in imports and fix pathbuf type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
majent4 committed Feb 12, 2024
1 parent a23c63c commit b4782c9
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/agent_data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use gethostname::gethostname;
use log::info;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use tracing::info;

#[derive(Debug, Deserialize, Serialize, Clone)]
struct AgentVersion {
Expand Down
13 changes: 9 additions & 4 deletions src/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
path::{Path, PathBuf},
time::SystemTime,
};
use tracing::warn;
use xxhash_rust::xxh3::xxh3_128;

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -129,9 +130,9 @@ pub fn create_file_info(path: &PathBuf) -> Option<FileInfo> {
})
}
Err(err) => {
warn!("Could not get access to {} metadata: {}", path, err);
warn!("Could not get access to {:?} metadata: {}", path, err);
None
},
}
}
}

Expand All @@ -157,14 +158,18 @@ mod tests {

#[test]
fn test_get_file_signature() {
let path = PathBuf::from(vec![r"tests", r"assets", r"test_folder", r"test-file-1"].iter().collect());
let path: PathBuf = [r"tests", r"assets", r"test_folder", r"test-file-1"]
.iter()
.collect();
let hash = get_file_signature(&path);
assert_eq!(hash, 53180848542178601830765469314885156230);
}

#[test]
fn test_create_file_info() {
let path = PathBuf::from(vec![r"tests", r"assets", r"test_folder", r"test-file-1"].iter().collect());
let path: PathBuf = [r"tests", r"assets", r"test_folder", r"test-file-1"]
.iter()
.collect();
if let Some(file_info) = create_file_info(&path) {
assert_eq!(file_info.path, path);
assert_eq!(file_info.size, 100);
Expand Down
2 changes: 1 addition & 1 deletion src/file_watcher.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use log::error;
use notify::RecursiveMode::Recursive as RecursiveWatcher;
use notify::Watcher;
use std::path::PathBuf;
use std::sync::mpsc;
use std::time;
use tracing::error;

pub fn watch_directories(
directories: Vec<PathBuf>,
Expand Down
3 changes: 1 addition & 2 deletions src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ use crate::my_files;
use crate::my_files::{ConfigurationPresent, ConnectionManagerPresent, Sealed};
use axum::{extract::Query, extract::State, routing::get, Json, Router};
use lazy_static::lazy_static;
use log::{error, info};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use tokio::net::TcpListener;
use tower_http::trace::{self, TraceLayer};
use tracing::Level;
use tracing::{error, info, Level};

lazy_static! {
static ref AGENT_LOGGING_LEVEL: HashMap<String, Level> = {
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ mod tidy_algo;

use crate::tidy_algo::tidy_algo::TidyAlgo;
use http_server::HttpServerBuilder;
use log::{error, info};
use notify::EventKind;
use std::{path::PathBuf, thread};
use tracing::{error, info};

pub async fn run() {
match std::env::var("TIDY_BACKTRACE") {
Expand Down Expand Up @@ -41,8 +41,9 @@ pub async fn run() {
info!("MyFilesDB sucessfully initialized");

let mut tidy_algo = TidyAlgo::new();
let basic_ruleset_path: PathBuf = [r"config", r"rules", r"basic.yml"].iter().collect();
info!("TidyAlgo sucessfully created");
tidy_algo.load_rules_from_file(&my_files, PathBuf::from(vec![r"config", r"rules", r"basic.yml"].iter().collect()));
tidy_algo.load_rules_from_file(&my_files, basic_ruleset_path);
info!("TidyAlgo sucessfully loaded rules from config/rules/basic.yml");

list_directories(config.file_lister_config.dir, &my_files);
Expand Down
2 changes: 1 addition & 1 deletion src/my_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use crate::file_info::{FileInfo, TidyScore};
use chrono::{DateTime, Utc};
use core::marker::PhantomData;
use itertools::{Either, Itertools};
use log::{error, info, warn};
use r2d2::{Pool, PooledConnection};
use r2d2_sqlite::SqliteConnectionManager;
use rusqlite::{params, Result, ToSql};
use std::path;
use std::path::PathBuf;
use tracing::{error, info, warn};

// region: --- MyFiles builder states
#[derive(Default, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/tidy_algo/tidy_algo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::tidy_algo::tidy_rules::duplicated::duplicated;
use crate::tidy_algo::tidy_rules::misnamed::misnamed;
use crate::tidy_algo::tidy_rules::perished::perished;
use config::{Config, ConfigError, File, Value};
use log::debug;
use std::collections::HashMap;
use std::path;
use tracing::debug;

/// Represents a rule that can be applied to a file
#[allow(dead_code)]
Expand Down
5 changes: 2 additions & 3 deletions src/tidy_algo/tidy_rules/duplicated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;

use config::Value;
use log::error;
use std::collections::HashMap;
use tracing::error;

use crate::{
file_info::{FileInfo, TidyScore},
Expand Down
2 changes: 1 addition & 1 deletion src/tidy_algo/tidy_rules/misnamed.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use config::Value;
use log::warn;
use regex::Regex;
use std::collections::HashMap;
use tracing::warn;

use crate::{
file_info::{FileInfo, TidyScore},
Expand Down
2 changes: 1 addition & 1 deletion src/tidy_algo/tidy_rules/perished.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use config::Value;
use lazy_static::lazy_static;
use log::warn;
use std::collections::HashMap;
use tracing::warn;

use crate::{
file_info::{FileInfo, TidyScore},
Expand Down

0 comments on commit b4782c9

Please sign in to comment.