rust_filesearch/models/
entry.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4
5/// Represents a filesystem entry with metadata
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct Entry {
8    pub path: PathBuf,
9    pub name: String,
10    pub size: u64,
11    pub kind: EntryKind,
12    #[serde(with = "chrono::serde::ts_seconds")]
13    pub mtime: DateTime<Utc>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub perms: Option<String>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub owner: Option<String>,
18    pub depth: usize,
19}
20
21/// File system entry types
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
23#[serde(rename_all = "lowercase")]
24pub enum EntryKind {
25    File,
26    Dir,
27    Symlink,
28}
29
30impl EntryKind {
31    pub fn from_metadata(metadata: &std::fs::Metadata) -> Self {
32        let file_type = metadata.file_type();
33        if file_type.is_symlink() {
34            EntryKind::Symlink
35        } else if file_type.is_dir() {
36            EntryKind::Dir
37        } else {
38            EntryKind::File
39        }
40    }
41}
42
43/// Watch events
44#[cfg(feature = "watch")]
45#[derive(Debug, Clone, Serialize)]
46pub struct WatchEvent {
47    pub event: String,
48    pub path: PathBuf,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub mtime: Option<DateTime<Utc>>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub size: Option<u64>,
53}