SafetyManager

Struct SafetyManager 

Source
pub struct SafetyManager {
    config: SafetyConfig,
    index_hash: String,
    trash_dir: PathBuf,
    history_file: PathBuf,
    trash_cache: Arc<RwLock<Vec<TrashEntry>>>,
}
Expand description

Safety manager for protecting file operations.

Fields§

§config: SafetyConfig

Configuration

§index_hash: String

Index hash (used for separating trash/history by index)

§trash_dir: PathBuf

Trash directory

§history_file: PathBuf

History file

§trash_cache: Arc<RwLock<Vec<TrashEntry>>>

In-memory cache of trash entries

Implementations§

Source§

impl SafetyManager

Source

pub fn new(source: &PathBuf, config: Option<SafetyConfig>) -> Self

Create a new safety manager.

Source

pub fn index_hash(&self) -> &str

Get the index hash.

Source

fn load_trash_entries(trash_dir: &PathBuf) -> Result<Vec<TrashEntry>>

Load trash entries from disk.

Source

async fn save_trash_entries(&self) -> Result<()>

Save trash entries to disk.

Source

pub async fn soft_delete(&self, path: &PathBuf) -> Result<TrashEntry, String>

Move a file to trash (soft delete).

Source

pub async fn restore(&self, trash_id: Uuid) -> Result<PathBuf, String>

Restore a file from trash.

Source

pub async fn list_trash(&self) -> Vec<TrashEntry>

List all trash entries.

Source

pub async fn get_trash_entry(&self, id: Uuid) -> Option<TrashEntry>

Get a specific trash entry.

Source

pub fn get_trash_content(&self, id: Uuid) -> Result<Vec<u8>, String>

Get trash content by ID.

Source

pub async fn purge_expired(&self) -> usize

Purge expired trash entries.

Source

pub fn log(&self, entry: HistoryEntry) -> Result<()>

Log an operation to history.

Source

pub fn log_success( &self, operation: HistoryOperation, undo_data: Option<UndoData>, )

Log a successful operation.

Source

pub fn log_failure(&self, operation: HistoryOperation, error: String)

Log a failed operation.

Source

pub fn read_history(&self, limit: Option<usize>) -> Vec<HistoryEntry>

Read history entries.

Source

pub fn get_history_json(&self, limit: Option<usize>) -> Vec<u8>

Get history as JSON bytes (for FUSE read).

Source

pub fn find_operation(&self, id: Uuid) -> Option<HistoryEntry>

Find an operation by ID for undo.

Source

pub async fn undo(&self, operation_id: Uuid) -> Result<String, String>

Undo an operation.

Source

pub fn soft_delete_enabled(&self) -> bool

Check if soft delete is enabled.

Source

pub fn trash_dir(&self) -> &PathBuf

Get trash directory path.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more