extern crate libc;
use chrono::{DateTime, Local};
use std::os::unix::fs::PermissionsExt;
use std::{error::Error, path::PathBuf};
#[derive(Debug)]
pub struct Entry {
is_dir: bool,
mode: u32,
size: f64,
modified: DateTime<Local>,
path: PathBuf,
}
impl Entry {
pub fn new(path: PathBuf) -> Result<Self, Box<dyn Error>> {
if !path.exists() {
return Err(Box::from(format!(
"Path doesn't exists or syslink is broken. Path: {:?}",
path
)));
}
let metadata = path.metadata()?;
let is_dir = metadata.is_dir();
let mode = metadata.permissions().mode();
let size = metadata.len() as f64;
let modified: DateTime<Local> = DateTime::from(metadata.modified()?);
Ok(Self {
is_dir,
mode,
size,
modified,
path,
})
}
}