From c20ce9bf74fcd98f0361e7cb03e634135632037d Mon Sep 17 00:00:00 2001 From: shutefan Date: Wed, 4 Oct 2017 21:43:06 +0200 Subject: [PATCH 1/5] cp: fix compiler warnings Fixes seven compiler warnings in cp.rs: - unused imports: `c_char`, `c_int` -> removed - value assigned to `inode` is never read -> no more default value, immutable - value assigned to `nlinks` is never read -> no more default value, immutable - unused variable: `src_path` -> removed - unused `std::result::Result` which must be used -> only in error on unsupported platforms (Windows) which is already handled with #[cfg(unix)] - variable `preserve_context` is assigned to, but never used -> removed - value assigned to `preserve_context` is never read -> see above, remove --- src/cp/cp.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/cp/cp.rs b/src/cp/cp.rs index 1730ad43b..a995c7bbd 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -50,9 +50,6 @@ use std::fs::File; use std::fs::OpenOptions; use filetime::FileTime; -#[cfg(target_os = "linux")] -use libc::{c_int, c_char}; - #[cfg(unix)] use std::os::unix::fs::PermissionsExt; #[cfg(target_os = "linux")] ioctl!(write ficlone with 0x94, 9; std::os::raw::c_int); @@ -681,8 +678,8 @@ fn preserve_hardlinks(hard_links: &mut Vec<(String, u64)>, source: &std::path::P if !source.is_dir() { unsafe { let src_path = CString::new(source.as_os_str().to_str().unwrap()).unwrap(); - let mut inode: u64 = 0; - let mut nlinks = 0; + let inode: u64; + let nlinks: u64; #[cfg(unix)] { let mut stat = mem::zeroed(); @@ -750,7 +747,6 @@ fn copy(sources: &[Source], target: &Target, options: &Options) -> CopyResult<() let mut found_hard_link = false; if preserve_hard_links { let dest = construct_dest_path(source, target, &target_type, options)?; - let src_path = CString::new(Path::new(&source.clone()).as_os_str().to_str().unwrap()).unwrap(); preserve_hardlinks(&mut hard_links, source, dest, &mut found_hard_link).unwrap(); } if !found_hard_link { @@ -907,7 +903,7 @@ fn copy_attribute(source: &Path, dest: &Path, attribute: &Attribute) -> CopyResu let xattrs = xattr::list(source)?; for attr in xattrs { if let Some(attr_value) = xattr::get(source, attr.clone())? { - xattr::set(dest, attr, &attr_value[..]); + crash_if_err!(EXIT_ERR, xattr::set(dest, attr, &attr_value[..])); } } } @@ -988,13 +984,6 @@ fn copy_file(source: &Path, dest: &Path, options: &Options) -> CopyResult<()> { println!("{}", context_for(source, dest)); } - let mut preserve_context = false; - for attribute in &options.preserve_attributes { - if *attribute == Attribute::Context { - preserve_context = true; - } - } - match options.copy_mode { CopyMode::Link => { fs::hard_link(source, dest).context(&*context_for(source, dest))?; From 83d25c0c70984b58f0e3611dcce665681c700c08 Mon Sep 17 00:00:00 2001 From: shutefan Date: Wed, 4 Oct 2017 23:17:11 +0200 Subject: [PATCH 2/5] cp: cast nNumberOfLinks to u64 --- src/cp/cp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cp/cp.rs b/src/cp/cp.rs index a995c7bbd..5bedb9718 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -701,7 +701,7 @@ fn preserve_hardlinks(hard_links: &mut Vec<(String, u64)>, source: &std::path::P return Err(format!("cannot get file information {:?}: {}", source, std::io::Error::last_os_error()).into()); } inode = (((*stat).nFileIndexHigh as u64) << 32 | (*stat).nFileIndexLow as u64); - nlinks = (*stat).nNumberOfLinks; + nlinks = (*stat).nNumberOfLinks as u64; } for hard_link in hard_links.iter() { From 82d6d24a97355072a63a0e10171d2b15c50ed98d Mon Sep 17 00:00:00 2001 From: shutefan Date: Thu, 5 Oct 2017 20:34:08 +0200 Subject: [PATCH 3/5] cp: cast st_ino and st_nlink to u64 --- src/cp/cp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cp/cp.rs b/src/cp/cp.rs index 5bedb9718..3e83b26cd 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -686,8 +686,8 @@ fn preserve_hardlinks(hard_links: &mut Vec<(String, u64)>, source: &std::path::P if libc::lstat(src_path.as_ptr(), &mut stat) < 0 { return Err(format!("cannot stat {:?}: {}", src_path, std::io::Error::last_os_error()).into()); } - inode = stat.st_ino; - nlinks = stat.st_nlink; + inode = stat.st_ino as u64; + nlinks = stat.st_nlink as u64; } #[cfg(windows)] { From e1d41b84f3eaf09384d108ed12c42a6c3edad2d0 Mon Sep 17 00:00:00 2001 From: shutefan Date: Fri, 6 Oct 2017 00:49:43 +0200 Subject: [PATCH 4/5] travis: fix compiler warnings for 1.22 --- src/comm/comm.rs | 4 ++-- src/printf/tokenize/unescaped_text.rs | 2 +- src/unexpand/unexpand.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/comm/comm.rs b/src/comm/comm.rs index 749daa501..98f5b742b 100644 --- a/src/comm/comm.rs +++ b/src/comm/comm.rs @@ -65,9 +65,9 @@ fn comm(a: &mut LineReader, b: &mut LineReader, opts: &getopts::Matches) { let delim : Vec = (0 .. 4).map(|col| mkdelim(col, opts)).collect(); - let mut ra = &mut String::new(); + let ra = &mut String::new(); let mut na = a.read_line(ra); - let mut rb = &mut String::new(); + let rb = &mut String::new(); let mut nb = b.read_line(rb); while na.is_ok() || nb.is_ok() { diff --git a/src/printf/tokenize/unescaped_text.rs b/src/printf/tokenize/unescaped_text.rs index 45f006fdf..50eecc8ec 100644 --- a/src/printf/tokenize/unescaped_text.rs +++ b/src/printf/tokenize/unescaped_text.rs @@ -179,7 +179,7 @@ impl UnescapedText { let mut new_text = UnescapedText::new(); let mut tmp_str = String::new(); { - let mut new_vec: &mut Vec = &mut (new_text.0); + let new_vec: &mut Vec = &mut (new_text.0); while let Some(ch) = it.next() { if !addchar { addchar = true; diff --git a/src/unexpand/unexpand.rs b/src/unexpand/unexpand.rs index 556f97119..dbbe417bd 100644 --- a/src/unexpand/unexpand.rs +++ b/src/unexpand/unexpand.rs @@ -137,7 +137,7 @@ fn next_tabstop(tabstops: &[usize], col: usize) -> Option { } } -fn write_tabs(mut output: &mut BufWriter, tabstops: &[usize], +fn write_tabs(output: &mut BufWriter, tabstops: &[usize], mut scol: usize, col: usize, prevtab: bool, init: bool, amode: bool) { // This conditional establishes the following: // We never turn a single space before a non-blank into From 4a96b56d60bd6709ad8057f0edbfc5b097aa252f Mon Sep 17 00:00:00 2001 From: shutefan Date: Fri, 6 Oct 2017 21:54:00 +0200 Subject: [PATCH 5/5] cp: keep --preserve related code but ignore "unused" warnings --- src/cp/cp.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cp/cp.rs b/src/cp/cp.rs index 3e83b26cd..fc51df701 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -984,6 +984,17 @@ fn copy_file(source: &Path, dest: &Path, options: &Options) -> CopyResult<()> { println!("{}", context_for(source, dest)); } + #[allow(unused)] + { + // TODO: implement --preserve flag + let mut preserve_context = false; + for attribute in &options.preserve_attributes { + if *attribute == Attribute::Context { + preserve_context = true; + } + } + } + match options.copy_mode { CopyMode::Link => { fs::hard_link(source, dest).context(&*context_for(source, dest))?;