mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 22:30:03 +00:00
Fix panic in atomic-file-install
(#1290)
Do not panic if path does not have a parent, instead return an error. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
2375ba48b6
commit
6c801a97ae
1 changed files with 11 additions and 2 deletions
|
@ -14,8 +14,17 @@ use std::os::unix::fs::symlink as symlink_file_inner;
|
|||
#[cfg(windows)]
|
||||
use std::os::windows::fs::symlink_file as symlink_file_inner;
|
||||
|
||||
fn parent(p: &Path) -> io::Result<&Path> {
|
||||
p.parent().ok_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
format!("`{}` does not have a parent", p.display()),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn copy_to_tempfile(src: &Path, dst: &Path) -> io::Result<NamedTempFile> {
|
||||
let parent = dst.parent().unwrap();
|
||||
let parent = parent(dst)?;
|
||||
debug!("Creating named tempfile at '{}'", parent.display());
|
||||
let tempfile = NamedTempFile::new_in(parent)?;
|
||||
|
||||
|
@ -125,7 +134,7 @@ pub fn atomic_symlink_file_noclobber(dest: &Path, link: &Path) -> io::Result<()>
|
|||
///
|
||||
/// This is a blocking function, must be called in `block_in_place` mode.
|
||||
pub fn atomic_symlink_file(dest: &Path, link: &Path) -> io::Result<()> {
|
||||
let parent = link.parent().unwrap();
|
||||
let parent = parent(link)?;
|
||||
|
||||
debug!("Creating tempPath at '{}'", parent.display());
|
||||
let temp_path = NamedTempFile::new_in(parent)?.into_temp_path();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue