Skip to main content

SymlinkManager

Struct SymlinkManager 

Source
pub struct SymlinkManager {
    pub tracking: SymlinkTracking,
    /* private fields */
}
Expand description

Manages symlinks for dotfile profiles

Fields§

§tracking: SymlinkTracking

Current tracking data

Implementations§

Source§

impl SymlinkManager

Source

pub fn new(repo_path: PathBuf) -> Result<Self>

Create a new SymlinkManager

Source

pub fn new_with_backup(repo_path: PathBuf, backup_enabled: bool) -> Result<Self>

Create a new SymlinkManager with backup settings

Source

pub fn new_with_config_dir( repo_path: PathBuf, backup_enabled: bool, config_dir: PathBuf, ) -> Result<Self>

Create a new SymlinkManager with a custom config directory.

This is primarily used for testing to avoid polluting the real user’s config directory with test data.

Source

pub fn activate_profile( &mut self, profile_name: &str, files: &[String], ) -> Result<Vec<SymlinkOperation>>

Activate a profile by creating all its symlinks

Source

pub fn deactivate_profile( &mut self, profile_name: &str, ) -> Result<Vec<SymlinkOperation>>

Deactivate a profile by removing its symlinks

Source

pub fn deactivate_profile_with_restore( &mut self, _profile_name: &str, restore_files: bool, ) -> Result<Vec<SymlinkOperation>>

Deactivate all symlinks, optionally restoring original files.

This deactivates the ENTIRE app - all profile symlinks AND common file symlinks. Useful for temporarily disabling dotstate or as a pre-uninstall step.

When restore_files is true, each symlink is replaced with a copy of the file from the repository, making it appear as if dotstate was never installed.

Source

pub fn switch_profile( &mut self, from: &str, to: &str, to_files: &[String], ) -> Result<SwitchReport>

Switch from one profile to another

Source

pub fn preview_switch( &self, from: &str, to: &str, to_files: &[String], ) -> Result<SwitchPreview>

Preview what would happen during a switch (dry run)

Source

pub fn save_tracking(&self) -> Result<()>

Save tracking data to disk

Source

pub fn get_active_profile(&self) -> Option<&str>

Get the currently active profile name Get the currently active profile name

Get all tracked symlinks Get all tracked symlinks

Source

pub fn rename_profile( &mut self, old_name: &str, new_name: &str, ) -> Result<Vec<SymlinkOperation>>

Rename a profile and update all associated symlinks This updates the source paths in the tracking file and recreates symlinks to point to the new profile folder location

Add a single symlink to an existing profile.

This is more efficient than calling activate_profile with a single file, as it doesn’t need to iterate or create unnecessary data structures.

§Arguments
  • profile_name - Name of the profile
  • relative_path - Path relative to home directory (e.g., “.zshrc”)
§Returns

The symlink operation result

Ensure all files in a profile have their symlinks created.

This is an efficient “reconciliation” method that only creates symlinks for files that are missing them. It’s perfect for after pulling changes from remote, where new files may have been added but their symlinks don’t exist locally yet.

Unlike activate_profile, this does NOT remove any existing symlinks - it only adds missing ones.

§Arguments
  • profile_name - Name of the profile
  • files - List of files that should have symlinks (relative paths)
§Returns

A tuple of (created_count, skipped_count, errors)

Remove a specific symlink from tracking without affecting other symlinks.

This is a surgical operation that only updates the tracking data for a single file, unlike deactivate_profile which removes all symlinks for a profile.

§Arguments
  • profile_name - Name of the profile
  • relative_path - Path relative to home directory (e.g., “.zshrc”)
§Returns

Result indicating success or failure

Add a symlink for a common file (shared across all profiles).

Common files are stored in the “common” folder at the repository root and are symlinked regardless of which profile is active.

§Arguments
  • relative_path - Path relative to home directory (e.g., “.gitconfig”)
§Returns

The symlink operation result

Remove a symlink for a common file and restore original if exists.

§Arguments
  • relative_path - Path relative to home directory (e.g., “.gitconfig”)
§Returns

The symlink operation result

Remove a common symlink from tracking only (without touching the actual symlink).

§Arguments
  • relative_path - Path relative to home directory

Ensure all common files have their symlinks created.

This is an efficient “reconciliation” method for common files.

§Arguments
  • files - List of common files that should have symlinks (relative paths)
§Returns

A tuple of (created_count, skipped_count, errors)

Source

pub fn activate_common_files( &mut self, files: &[String], ) -> Result<Vec<SymlinkOperation>>

Activate all common files by creating their symlinks.

§Arguments
  • files - List of common files to activate
§Returns

List of symlink operations

Check if a symlink is for a common file.

§Arguments
  • source_path - The source path of the symlink
§Returns

True if the symlink is for a common file

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> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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