Skip to content

Commit

Permalink
feat(iroh): use reflink if possible (#1581)
Browse files Browse the repository at this point in the history
reflink-copy is a clone of the abandoned reflink crate. Last time there
were some failures on android, so let's see if it works now...

## Description

<!-- A summary of what this pull request achieves and a rough list of
changes. -->

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [ ] Self-review.
- [ ] Documentation updates if relevant.
- [ ] Tests if relevant.
  • Loading branch information
rklaehn authored Oct 5, 2023
1 parent 0b28d15 commit e2ee678
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ colored = { version = "2.0.4", optional = true }

# Examples
ed25519-dalek = { version = "2.0.0", features = ["serde", "rand_core"], optional = true }
reflink-copy = { version = "0.1.8", optional = true }

[features]
default = ["cli", "metrics"]
cli = ["clap", "config", "console", "dirs-next", "indicatif", "multibase", "quic-rpc/quinn-transport", "tokio/rt-multi-thread", "tracing-subscriber", "flat-db", "mem-db", "iroh-collection", "shell-words", "shellexpand", "rustyline", "colored", "toml", "human-time", "comfy-table"]
metrics = ["iroh-metrics"]
mem-db = []
flat-db = []
flat-db = ["reflink-copy"]
iroh-collection = []
test = []
example-sync = ["cli"]
Expand Down
12 changes: 10 additions & 2 deletions iroh/src/baomap/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,11 @@ impl Store {
let temp_path = self.temp_path();
// copy the data, since it is not stable
progress.try_send(ImportProgress::CopyProgress { id, offset: 0 })?;
std::fs::copy(&path, &temp_path)?;
if reflink_copy::reflink_or_copy(&path, &temp_path)?.is_none() {
tracing::debug!("reflinked {} to {}", path.display(), temp_path.display());
} else {
tracing::debug!("copied {} to {}", path.display(), temp_path.display());
}
ImportFile::TempFile(temp_path)
}
};
Expand Down Expand Up @@ -1165,7 +1169,11 @@ impl Store {
tracing::debug!("copying {} to {}", source.display(), target.display());
progress(0)?;
// todo: progress
std::fs::copy(&source, &target)?;
if reflink_copy::reflink_or_copy(&source, &target)?.is_none() {
tracing::debug!("reflinked {} to {}", source.display(), target.display());
} else {
tracing::debug!("copied {} to {}", source.display(), target.display());
}
progress(size)?;
let mut state = self.0.state.write().unwrap();
let Some(entry) = state.complete.get_mut(&hash) else {
Expand Down

0 comments on commit e2ee678

Please sign in to comment.