fn install_file(mode: u32, source: impl AsRef<Path>, dest_dir: impl AsRef<Path>) -> Result<(), String> {
	let source   = source.as_ref();
	let dest_dir = dest_dir.as_ref();
	let dest     = dest_dir.join(source.file_name().unwrap());

	eprintln!("{} {}",
		Paint::green("  Installing").bold(),
		dest.display()
	);

	std::fs::remove_file(&dest).or_else(|e| match e.kind() {
		std::io::ErrorKind::NotFound => Ok(()),
		_                            => Err(e),
	}).map_err(|e| format!("Failed to unlink destination file: {}: {}", dest.display(), e))?;


	use std::os::unix::fs::OpenOptionsExt;
	let mut source_file = std::fs::File::open(source).map_err(|e| format!("Failed to open file for reading: {}: {}", source.display(), e))?;
	let mut dest_file   = std::fs::OpenOptions::new()
		.read(false)
		.write(true)
		.create(true)
		.mode(mode)
		.custom_flags(libc::O_EXCL)
		.open(&dest)
		.map_err(|e| format!("Failed to open file for writing: {}: {}", dest.display(), e))?;

	std::io::copy(&mut source_file, &mut dest_file).map_err(|e| format!("Failed to copy data from {} to {}: {}", source.display(), dest.display(), e))?;

	Ok(())
}
/// Similar to std::fs::copy, but first unlinks the destination and opens then opens it with O_EXCL to make sure it's a new inode.
Similar to std::fs::copy, but first unlinks the destination and opens then opens it with O_EXCL to make sure it's a new inode.
Similar to std :: fs :: copy but first unlinks the destination and opens then opens it with O_EXCL to make sure it ' s a new inode .
fn install_file(mode: u32, source: impl AsRef<Path>, dest_dir: impl AsRef<Path>) -> Result<(), String> {
	let source   = source.as_ref();
	let dest_dir = dest_dir.as_ref();
	let dest     = dest_dir.join(source.file_name().unwrap());
	eprintln!("{} {}",
		Paint::green("  Installing").bold(),
		dest.display()
	);
	std::fs::remove_file(&dest).or_else(|e| match e.kind() {
		std::io::ErrorKind::NotFound => Ok(()),
		_                            => Err(e),
	}).map_err(|e| format!("Failed to unlink destination file: {}: {}", dest.display(), e))?;
	use std::os::unix::fs::OpenOptionsExt;
	let mut source_file = std::fs::File::open(source).map_err(|e| format!("Failed to open file for reading: {}: {}", source.display(), e))?;
	let mut dest_file   = std::fs::OpenOptions::new()
		.read(false)
		.write(true)
		.create(true)
		.mode(mode)
		.custom_flags(libc::O_EXCL)
		.open(&dest)
		.map_err(|e| format!("Failed to open file for writing: {}: {}", dest.display(), e))?;
	std::io::copy(&mut source_file, &mut dest_file).map_err(|e| format!("Failed to copy data from {} to {}: {}", source.display(), dest.display(), e))?;
	Ok(())
}
fn install_file ( mode : u32 , source : impl AsRef < Path > , dest_dir : impl AsRef < Path > ) -> Result < ( ) , String > { let source = source . as_ref ( ) ; let dest_dir = dest_dir . as_ref ( ) ; let dest = dest_dir . join ( source . file_name ( ) . unwrap ( ) ) ; eprintln ! ( " " Paint green ( " " ) bold ( ) dest display ( ) ) ; std :: fs :: remove_file ( & dest ) . or_else ( | e | match e . kind ( ) { std :: io :: ErrorKind :: NotFound => Ok ( ( ) ) , _ => Err ( e ) , } ) . map_err ( | e | format ! ( " " dest display ( ) e ) ) ? ; use std :: os :: unix :: fs :: OpenOptionsExt ; let mut source_file = std :: fs :: File :: open ( source ) . map_err ( | e | format ! ( " " source display ( ) e ) ) ? ; let mut dest_file = std :: fs :: OpenOptions :: new ( ) . read ( false ) . write ( true ) . create ( true ) . mode ( mode ) . custom_flags ( libc :: O_EXCL ) . open ( & dest ) . map_err ( | e | format ! ( " " dest display ( ) e ) ) ? ; std :: io :: copy ( & mut source_file , & mut dest_file ) . map_err ( | e | format ! ( " " source display ( ) dest display ( ) e ) ) ? ; Ok ( ( ) ) }
Similar to std::fs::copy, but first unlinks the destination and opens then opens it with O_EXCL to make sure it's a new inode.
Similar to std :: fs :: copy but first unlinks the destination and opens then opens it with O_EXCL to make sure it ' s a new inode .
mode
u32
source
impl AsRef<Path>
dest_dir
impl AsRef<Path>
mode
u32
source
impl AsRef<Path>
dest_dir
impl AsRef<Path>