mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Use reflink_copy::reflink_or_copy
in fs::atomic_install*
(#1197)
to speedup copy operation `atomic_install*`. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
b3b682a1af
commit
963e9e97ad
3 changed files with 28 additions and 5 deletions
19
Cargo.lock
generated
19
Cargo.lock
generated
|
@ -261,6 +261,7 @@ dependencies = [
|
||||||
"miette",
|
"miette",
|
||||||
"normalize-path",
|
"normalize-path",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"reflink-copy",
|
||||||
"semver",
|
"semver",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -2005,6 +2006,12 @@ dependencies = [
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ioctl-sys"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8bd11f3a29434026f5ff98c730b668ba74b1033637b8817940b54d040696133c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipconfig"
|
name = "ipconfig"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
|
@ -2750,6 +2757,18 @@ dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "reflink-copy"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c9c6f4912869a1c9abaf4038e7051d88544960da7c9560b8baeaabfa3c95e05b"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"ioctl-sys",
|
||||||
|
"libc",
|
||||||
|
"windows 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
|
|
|
@ -29,6 +29,7 @@ maybe-owned = "0.3.4"
|
||||||
miette = "5.9.0"
|
miette = "5.9.0"
|
||||||
normalize-path = { version = "0.2.1", path = "../normalize-path" }
|
normalize-path = { version = "0.2.1", path = "../normalize-path" }
|
||||||
once_cell = "1.18.0"
|
once_cell = "1.18.0"
|
||||||
|
reflink-copy = "0.1.5"
|
||||||
semver = { version = "1.0.17", features = ["serde"] }
|
semver = { version = "1.0.17", features = ["serde"] }
|
||||||
serde = { version = "1.0.163", features = ["derive"] }
|
serde = { version = "1.0.163", features = ["derive"] }
|
||||||
serde_json = "1.0.99"
|
serde_json = "1.0.99"
|
||||||
|
|
|
@ -1,24 +1,27 @@
|
||||||
use std::{fs, io, path::Path};
|
use std::{fs, io, path::Path};
|
||||||
|
|
||||||
|
use reflink_copy::reflink_or_copy;
|
||||||
use tempfile::{NamedTempFile, TempPath};
|
use tempfile::{NamedTempFile, TempPath};
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, warn};
|
||||||
|
|
||||||
fn copy_to_tempfile(src: &Path, dst: &Path) -> io::Result<NamedTempFile> {
|
fn copy_to_tempfile(src: &Path, dst: &Path) -> io::Result<NamedTempFile> {
|
||||||
let mut src_file = fs::File::open(src)?;
|
|
||||||
|
|
||||||
let parent = dst.parent().unwrap();
|
let parent = dst.parent().unwrap();
|
||||||
debug!("Creating named tempfile at '{}'", parent.display());
|
debug!("Creating named tempfile at '{}'", parent.display());
|
||||||
let mut tempfile = NamedTempFile::new_in(parent)?;
|
let tempfile = NamedTempFile::new_in(parent)?;
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Copying from '{}' to '{}'",
|
"Copying from '{}' to '{}'",
|
||||||
src.display(),
|
src.display(),
|
||||||
tempfile.path().display()
|
tempfile.path().display()
|
||||||
);
|
);
|
||||||
io::copy(&mut src_file, tempfile.as_file_mut())?;
|
// src and dst is likely to be on the same filesystem.
|
||||||
|
// Uses reflink if the fs support it, or fallback to
|
||||||
|
// `fs::copy` if it doesn't support it or it is not on the
|
||||||
|
// same filesystem.
|
||||||
|
reflink_or_copy(src, tempfile.path())?;
|
||||||
|
|
||||||
debug!("Retrieving permissions of '{}'", src.display());
|
debug!("Retrieving permissions of '{}'", src.display());
|
||||||
let permissions = src_file.metadata()?.permissions();
|
let permissions = src.metadata()?.permissions();
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Setting permissions of '{}' to '{permissions:#?}'",
|
"Setting permissions of '{}' to '{permissions:#?}'",
|
||||||
|
|
Loading…
Add table
Reference in a new issue