Skip to content

Commit

Permalink
feat: add reflink
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Dec 15, 2024
1 parent 955cf68 commit 68af427
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 6 deletions.
9 changes: 8 additions & 1 deletion BUILDLING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@
```console
git tag v0.1.0
git push --tags
```
```

## Test with dummay file

```console
dd if=/dev/zero of=dummy bs=1G count=5
mc dummy copied_dummy --verify
```
80 changes: 78 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ humansize = "2.1.3"
indicatif = "0.17.9"
keepawake = "0.5.1"
num_cpus = "1.16.0"
reflink-copy = "0.1.20"
sha256 = "1.5.0"
tracing = "0.1.41"
tracing-indicatif = "0.3.8"
Expand Down
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,31 @@ See installation options in [Mc Website](https://thewh1teagle.github.io/mc/) or

## Usage

See `--help`

<details>

<summary>Details</summary>

```console
dd if=/dev/zero of=dummy bs=2G count=10
mc dummy copied_dummy --verify
Copies files or directories with options for recursion and overwriting.

Usage: mc [OPTIONS] <SOURCE>... <DESTINATION>

Arguments:
<SOURCE>... Source file or directory to copy
<DESTINATION> Destination file or directory

Options:
-f, --force Overwrite destination if it exists
--hard-link Hard link file
--symlink Symbol link file
--reflink Ref link file Similar to hardlink except modify one doesn't affect the other
--verify Verify hash of folder / file once copied
--no-progress Disable progress bar
--no-keep-awake Disable keep system awake while copy
--keep-display-awake Keep display awake while copy
-h, --help Print help
```

</details>
5 changes: 5 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ pub struct Args {
#[arg(long)]
pub symlink: bool,

/// Ref link file
/// Similar to hardlink except modify one doesn't affect the other
#[arg(long)]
pub reflink: bool,

/// Verify hash of folder / file once copied
#[arg(long)]
pub verify: bool,
Expand Down
8 changes: 7 additions & 1 deletion src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn perform_copy_operation(
!args.no_progress,
args.symlink,
args.hard_link,
args.reflink,
source_path,
destination_path,
pb,
Expand Down Expand Up @@ -93,6 +94,7 @@ pub fn copy_file<P: AsRef<Path>>(
progress: bool,
symlink: bool,
hard_link: bool,
reflink: bool,
source_path: P,
destination_path: P,
pb: &Option<ProgressBar>,
Expand Down Expand Up @@ -122,7 +124,9 @@ pub fn copy_file<P: AsRef<Path>>(
} else {
let mut file_options = fs_extra::file::CopyOptions::new();
file_options.overwrite = force;
if progress {
if reflink {
reflink_copy::reflink_or_copy(source_path, destination_path)?;
} else if progress {
fs_extra::file::copy_with_progress(
source_path,
destination_path,
Expand Down Expand Up @@ -170,6 +174,7 @@ mod tests {
no_keep_awake: true,
source: vec![source_file.to_str().unwrap().to_string()],
verify: false,
reflink: false,
};

// Perform the copy operation
Expand Down Expand Up @@ -209,6 +214,7 @@ mod tests {
no_keep_awake: true,
source: vec![source_dir.to_str().unwrap().to_string()],
verify: false,
reflink: false,
};

// Perform the copy operation
Expand Down
3 changes: 3 additions & 0 deletions src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ mod tests {
hard_link: false,
keep_display_awake: false,
no_keep_awake: true,
reflink: false,
};

let result = ensure_valid_paths(&args);
Expand All @@ -82,6 +83,7 @@ mod tests {
hard_link: false,
keep_display_awake: false,
no_keep_awake: true,
reflink: false,
};

let result = ensure_valid_paths(&args);
Expand Down Expand Up @@ -118,6 +120,7 @@ mod tests {
hard_link: false,
keep_display_awake: false,
no_keep_awake: true,
reflink: false,
};

// Ensure that the destination directory doesn't exist before the test
Expand Down

0 comments on commit 68af427

Please sign in to comment.