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()?;§Create Symlinks
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>
impl<'a> Modify<'a>
Sourcepub fn new(repo: &'a Repository) -> Self
pub fn new(repo: &'a Repository) -> Self
Create a new Modify builder for the given repository.
Set the commit author (required).
Sourcepub fn copy_dir(self, src: &str, dst: &str) -> Self
pub fn copy_dir(self, src: &str, dst: &str) -> Self
Copy a directory and all its contents recursively.
Sourcepub fn rename(self, old_path: &str, new_path: &str) -> Self
pub fn rename(self, old_path: &str, new_path: &str) -> Self
Rename a file (alias for move_file).
Sourcepub fn delete_file(self, path: &str) -> Self
pub fn delete_file(self, path: &str) -> Self
Delete a file.
Sourcepub fn delete_dir(self, path: &str) -> Self
pub fn delete_dir(self, path: &str) -> Self
Delete a directory and all its contents.
Sourcepub fn delete_matching(self, pattern: &str) -> Self
pub fn delete_matching(self, pattern: &str) -> Self
Delete all files matching a glob pattern.
Sourcepub fn chmod(self, path: &str, mode: u32) -> Self
pub fn chmod(self, path: &str, mode: u32) -> Self
Change file permissions using octal notation.
Sourcepub fn chmod_permissions(self, path: &str, perms: Permissions) -> Self
pub fn chmod_permissions(self, path: &str, perms: Permissions) -> Self
Change permissions using a Permissions struct.
Sourcepub fn chmod_dir(self, path: &str, mode: u32) -> Self
pub fn chmod_dir(self, path: &str, mode: u32) -> Self
Change permissions for all files in a directory recursively.
Sourcepub fn make_executable(self, path: &str) -> Self
pub fn make_executable(self, path: &str) -> Self
Make a file executable (sets mode to 755).
Sourcepub fn symlink_file(self, link_path: &str, target_file: &str) -> Self
pub fn symlink_file(self, link_path: &str, target_file: &str) -> Self
Create a symbolic link to a file (alias for symlink).
Sourcepub fn symlink_dir(self, link_path: &str, target_dir: &str) -> Self
pub fn symlink_dir(self, link_path: &str, target_dir: &str) -> Self
Create a symbolic link to a directory (alias for symlink).