Skip to main content

BondManager

Struct BondManager 

Source
pub struct BondManager { /* private fields */ }
Expand description

SQLite-backed manager for Bonds. The BondManager struct provides high-level methods for managing the lifecycle of bonds, including creating, retrieving, updating, and deleting bonds. It handles the underlying SQLite database connection and schema management, as well as the filesystem operations required to create and update symlinks. The manager ensures that bond records are kept in sync with the actual state of the filesystem and provides error handling for various edge cases, such as invalid paths or conflicts with existing files.

Implementations§

Source§

impl BondManager

Source

pub fn new(db_path: Option<PathBuf>) -> Result<Self, BondError>

Open (or create) the DB at db_path. If None, defaults to $HOME/.bonds/bonds.db.

Source

pub fn list_bonds(&self) -> Result<Vec<Bond>, BondError>

List all bonds (most-recent first).

Source

pub fn get_bond(&self, identifier: &str) -> Result<Bond, BondError>

Get a single bond by ID or name. ID can be a unique prefix. First tries exact name match, then falls back to ID prefix match. Errors if not found or if ID prefix is ambiguous. This method is used by CLI commands that accept either an ID or name as an identifier for a bond.

Source

pub fn create_bond<P: AsRef<Path>, Q: AsRef<Path>>( &self, source: P, target: Q, name: Option<String>, ) -> Result<Bond, BondError>

Create a symlink bond and persist it (no metadata). This is the main method used by CLI commands to create bonds, and it keeps the signature simple for that use case. Library users who want metadata can call create_bond_with_metadata instead.

Source

pub fn create_bond_with_metadata<P: AsRef<Path>, Q: AsRef<Path>>( &self, source: P, target: Q, name: Option<String>, metadata: Option<HashMap<String, String>>, ) -> Result<Bond, BondError>

Create a symlink bond with metadata and persist it. This method is intended for library users who want to set metadata at creation time. It has a more complex signature than create_bond, but it avoids the need for a separate “update metadata” call after creation.

Source

pub fn update_bond( &self, id: &str, new_source: Option<PathBuf>, new_target: Option<PathBuf>, new_name: Option<String>, ) -> Result<Bond, BondError>

Update a bond’s source and/or target. Replaces the symlink on disk and updates the DB record. This method is used by the CLI update command to modify the source or target paths of an existing bond. It validates the new paths, ensures that the target path does not conflict with existing files, updates the symlink on disk, and then updates the corresponding record in the SQLite database. The method returns the updated Bond object after successful completion.

Source

pub fn update_bond_metadata( &self, identifier: &str, metadata: Option<HashMap<String, String>>, ) -> Result<Bond, BondError>

Replace a bond’s metadata. Pass None to clear metadata entirely. This method is used by the CLI command to update the metadata of an existing bond. It accepts a bond identifier (ID or name) and a new metadata map, which can be set to None to clear existing metadata. The method updates the metadata in the SQLite database and returns the updated Bond object with the new metadata. This allows users to manage custom key/value pairs associated with their bonds without affecting the source or target paths.

Source

pub fn delete_bond( &self, id: &str, remove_target: bool, ) -> Result<Bond, BondError>

Delete a bond by id. If remove_target is true, non-symlink targets are removed too. This method is used by the CLI delete command to remove an existing bond. It first retrieves the bond by its identifier, checks if the target path exists, and if it does, it determines whether it’s a symlink or a regular file/directory. If it’s a symlink, it removes it. If it’s not a symlink and remove_target is true, it removes the file or directory at the target path. Finally, it deletes the bond record from the SQLite database and returns the deleted Bond object. This allows users to clean up bonds and optionally remove the target files/directories they point to.

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.

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.