77#![ allow( clippy:: extra_unused_lifetimes) ]
88
99use quick_error:: quick_error;
10- use std:: borrow:: Cow ;
1110use std:: cmp:: Ordering ;
1211use std:: collections:: { HashMap , HashSet } ;
1312use std:: env;
@@ -41,8 +40,8 @@ use uucore::{backup_control, update_control};
4140// requires these enum.
4241pub use uucore:: { backup_control:: BackupMode , update_control:: UpdateMode } ;
4342use uucore:: {
44- crash , format_usage, help_about, help_section, help_usage, prompt_yes, show_error,
45- show_warning , util_name,
43+ format_usage, help_about, help_section, help_usage, prompt_yes, show_error, show_warning ,
44+ util_name,
4645} ;
4746
4847use crate :: copydir:: copy_directory;
@@ -144,6 +143,7 @@ pub enum SparseMode {
144143}
145144
146145/// The expected file type of copy target
146+ #[ derive( Copy , Clone ) ]
147147pub enum TargetType {
148148 Directory ,
149149 File ,
@@ -1195,7 +1195,7 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult
11951195 & progress_bar,
11961196 source,
11971197 target,
1198- & target_type,
1198+ target_type,
11991199 options,
12001200 & mut symlinked_files,
12011201 & mut copied_files,
@@ -1220,7 +1220,7 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult
12201220fn construct_dest_path (
12211221 source_path : & Path ,
12221222 target : & Path ,
1223- target_type : & TargetType ,
1223+ target_type : TargetType ,
12241224 options : & Options ,
12251225) -> CopyResult < PathBuf > {
12261226 if options. no_target_dir && target. is_dir ( ) {
@@ -1235,7 +1235,7 @@ fn construct_dest_path(
12351235 return Err ( "with --parents, the destination must be a directory" . into ( ) ) ;
12361236 }
12371237
1238- Ok ( match * target_type {
1238+ Ok ( match target_type {
12391239 TargetType :: Directory => {
12401240 let root = if options. parents {
12411241 Path :: new ( "" )
@@ -1252,7 +1252,7 @@ fn copy_source(
12521252 progress_bar : & Option < ProgressBar > ,
12531253 source : & Path ,
12541254 target : & Path ,
1255- target_type : & TargetType ,
1255+ target_type : TargetType ,
12561256 options : & Options ,
12571257 symlinked_files : & mut HashSet < FileInformation > ,
12581258 copied_files : & mut HashMap < FileInformation , PathBuf > ,
@@ -1995,24 +1995,12 @@ fn copy_link(
19951995) -> CopyResult < ( ) > {
19961996 // Here, we will copy the symlink itself (actually, just recreate it)
19971997 let link = fs:: read_link ( source) ?;
1998- let dest: Cow < ' _ , Path > = if dest. is_dir ( ) {
1999- match source. file_name ( ) {
2000- Some ( name) => dest. join ( name) . into ( ) ,
2001- None => crash ! (
2002- EXIT_ERR ,
2003- "cannot stat {}: No such file or directory" ,
2004- source. quote( )
2005- ) ,
2006- }
2007- } else {
2008- // we always need to remove the file to be able to create a symlink,
2009- // even if it is writeable.
2010- if dest. is_symlink ( ) || dest. is_file ( ) {
2011- fs:: remove_file ( dest) ?;
2012- }
2013- dest. into ( )
2014- } ;
2015- symlink_file ( & link, & dest, & context_for ( & link, & dest) , symlinked_files)
1998+ // we always need to remove the file to be able to create a symlink,
1999+ // even if it is writeable.
2000+ if dest. is_symlink ( ) || dest. is_file ( ) {
2001+ fs:: remove_file ( dest) ?;
2002+ }
2003+ symlink_file ( & link, dest, & context_for ( & link, dest) , symlinked_files)
20162004}
20172005
20182006/// Generate an error message if `target` is not the correct `target_type`
0 commit comments