Modify

Struct Modify 

Source
pub struct Modify<'a> { /* private fields */ }
Expand description

Builder for filesystem modification operations.

All operations are staged and then committed atomically when execute() is called.

§Examples

§Copy and Move Files

use heroforge_core::Repository;
use heroforge_core::fs::Modify;

let repo = Repository::open_rw("project.forge")?;

let hash = Modify::new(&repo)
    .message("Reorganize project structure")
    .author("developer")
    .copy_file("README.md", "docs/README.md")
    .copy_dir("src", "src_backup")
    .move_file("old_name.rs", "new_name.rs")
    .move_dir("scripts", "tools")
    .execute()?;

§Delete Files

let hash = Modify::new(&repo)
    .message("Clean up old files")
    .author("developer")
    .delete_file("deprecated.rs")
    .delete_dir("old_module")
    .delete_matching("**/*.bak")
    .execute()?;

§Change Permissions

let hash = Modify::new(&repo)
    .message("Fix permissions")
    .author("developer")
    .make_executable("scripts/build.sh")
    .chmod("config.toml", 0o644)
    .chmod_dir("bin", 0o755)
    .execute()?;
let hash = Modify::new(&repo)
    .message("Add convenience symlinks")
    .author("developer")
    .symlink("build", "scripts/build.sh")
    .symlink("latest", "releases/v1.0.0")
    .execute()?;

§Write Files

let hash = Modify::new(&repo)
    .message("Update configuration")
    .author("developer")
    .write_str("VERSION", "1.0.0\n")
    .write("data.bin", &[0x00, 0x01, 0x02])
    .touch(".gitkeep")
    .execute()?;

Implementations§

Source§

impl<'a> Modify<'a>

Source

pub fn new(repo: &'a Repository) -> Self

Create a new Modify builder for the given repository.

Source

pub fn at_commit(self, hash: &str) -> Self

Apply operations starting from a specific commit.

Source

pub fn on_trunk(self) -> Self

Apply operations to trunk tip (default).

Source

pub fn on_branch(self, branch: &str) -> Result<Self>

Apply operations to a branch tip.

Source

pub fn message(self, msg: &str) -> Self

Set the commit message (required).

Source

pub fn author(self, author: &str) -> Self

Set the commit author (required).

Source

pub fn copy_file(self, src: &str, dst: &str) -> Self

Copy a file to a new location.

Source

pub fn copy_dir(self, src: &str, dst: &str) -> Self

Copy a directory and all its contents recursively.

Source

pub fn move_file(self, src: &str, dst: &str) -> Self

Move or rename a file.

Source

pub fn move_dir(self, src: &str, dst: &str) -> Self

Move or rename a directory.

Source

pub fn rename(self, old_path: &str, new_path: &str) -> Self

Rename a file (alias for move_file).

Source

pub fn delete_file(self, path: &str) -> Self

Delete a file.

Source

pub fn delete_dir(self, path: &str) -> Self

Delete a directory and all its contents.

Source

pub fn delete_matching(self, pattern: &str) -> Self

Delete all files matching a glob pattern.

Source

pub fn chmod(self, path: &str, mode: u32) -> Self

Change file permissions using octal notation.

Source

pub fn chmod_permissions(self, path: &str, perms: Permissions) -> Self

Change permissions using a Permissions struct.

Source

pub fn chmod_dir(self, path: &str, mode: u32) -> Self

Change permissions for all files in a directory recursively.

Source

pub fn make_executable(self, path: &str) -> Self

Make a file executable (sets mode to 755).

Create a symbolic link.

Create a symbolic link to a file (alias for symlink).

Create a symbolic link to a directory (alias for symlink).

Source

pub fn write(self, path: &str, content: &[u8]) -> Self

Write binary content to a file.

Source

pub fn write_str(self, path: &str, content: &str) -> Self

Write a string to a file.

Source

pub fn touch(self, path: &str) -> Self

Create an empty file or update its timestamp.

Source

pub fn execute(self) -> Result<String>

Execute all staged operations and create a commit.

Source

pub fn preview(&self) -> Result<Preview>

Preview the operations without committing.

Auto Trait Implementations§

§

impl<'a> Freeze for Modify<'a>

§

impl<'a> !RefUnwindSafe for Modify<'a>

§

impl<'a> !Send for Modify<'a>

§

impl<'a> !Sync for Modify<'a>

§

impl<'a> Unpin for Modify<'a>

§

impl<'a> !UnwindSafe for Modify<'a>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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

Source§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.