New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cp: add support for --attributes-only and setting timestamps, links and xattrs #1066
Conversation
Matt8898
commented
Aug 7, 2017
•
edited
edited
- Add windows support
- Implement --preserve
- Implement preserving Links and xattrs
src/cp/cp.rs
Outdated
let dest_path = CString::new(dest.as_os_str().to_str().unwrap()).unwrap(); | ||
unsafe { | ||
let mut stat: libc::stat = mem::zeroed(); | ||
libc::stat(src_path.as_ptr(), &mut stat); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use the filetime
crate to get and set the times; that should be more portable, and work on Windows and Redox.
src/cp/cp.rs
Outdated
modtime: stat.st_mtime | ||
}); | ||
} | ||
let metadata = fs::metadata(source).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably use ?
instead of .unwrap()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it took me so long to get around to reviewing this.
src/cp/cp.rs
Outdated
extern crate clap; | ||
extern crate walkdir; | ||
extern crate filetime; | ||
use filetime::FileTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please separate the extern crate
and use
statements into separate sections (with the use
section below the extern crate
one).
src/cp/cp.rs
Outdated
preserve_hard_links = true; | ||
} | ||
} | ||
#[cfg(unix)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a newline before #[cfg(unix)]
please.
src/cp/cp.rs
Outdated
} else { | ||
let mut found_hard_link = false; | ||
if preserve_hard_links { | ||
#[cfg(unix)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather this #[cfg(unix)]
section and the #[cfg(windows)]
section below be split off into separate functions.
src/cp/cp.rs
Outdated
|
||
let file_index = ((*file_info).nFileIndexHigh, (*file_info).nFileIndexLow); | ||
for hard_link in &hard_links { | ||
if (hard_link.1).0 == file_index.0 && (hard_link.1).1 == file_index.1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the parentheses here necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean the parentheses for the tuples then yes, they are necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix the other ones
src/cp/cp.rs
Outdated
found_hard_link = true; | ||
} | ||
} | ||
if (((*file_info).nNumberOfLinks) > 1u32) && !found_hard_link { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove the outer parentheses here.
src/cp/cp.rs
Outdated
if non_fatal_errors { | ||
Err(Error::NotAllFilesCopied) | ||
return Err(Error::NotAllFilesCopied) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return
here is not necessary.
src/cp/cp.rs
Outdated
} else { | ||
Ok(()) | ||
return Ok(()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
src/cp/cp.rs
Outdated
copy_file(path.as_path(), local_to_target.as_path(), options)?; | ||
if preserve_hard_links { | ||
#[cfg(unix)] | ||
unsafe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both this #[cfg(unix)]
section and the #[cfg(windows)]
section below seem to share code with the sections in copy()
. Maybe try to move some of the code into common functions?
No problem, I updated it. |
@Arcterus Is anything still blocking this from being merged? |
No, I just have been too busy with school lately. Sorry that it's taken me so long to look at this. |
No problem. |