Skip to content
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

Merged
merged 8 commits into from Oct 1, 2017
Merged

Conversation

Matt8898
Copy link
Contributor

@Matt8898 Matt8898 commented Aug 7, 2017

  • Add windows support
  • Implement --preserve
  • Implement preserving Links and xattrs

@Matt8898 Matt8898 changed the title cp: add support for --attributes-only, --preserve and preserving timestamps cp: add support for --attributes-only and preserving timestamps Aug 7, 2017
@Matt8898 Matt8898 changed the title cp: add support for --attributes-only and preserving timestamps cp: add support for --attributes-only and setting timestamps Aug 7, 2017
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);
Copy link
Contributor

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();
Copy link
Contributor

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().

@Matt8898 Matt8898 closed this Aug 23, 2017
@Matt8898 Matt8898 reopened this Aug 23, 2017
@Matt8898 Matt8898 closed this Aug 24, 2017
@Matt8898 Matt8898 reopened this Aug 24, 2017
@Matt8898 Matt8898 changed the title cp: add support for --attributes-only and setting timestamps cp: add support for --attributes-only and setting timestamps, links and xattrs Aug 24, 2017
Copy link
Collaborator

@Arcterus Arcterus left a 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;
Copy link
Collaborator

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)]
Copy link
Collaborator

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)]
Copy link
Collaborator

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 {
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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 {
Copy link
Collaborator

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)
Copy link
Collaborator

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(())
Copy link
Collaborator

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 {
Copy link
Collaborator

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?

@Matt8898
Copy link
Contributor Author

No problem, I updated it.

@ids1024
Copy link
Contributor

ids1024 commented Sep 25, 2017

@Arcterus Is anything still blocking this from being merged?

@Arcterus
Copy link
Collaborator

Arcterus commented Oct 1, 2017

No, I just have been too busy with school lately. Sorry that it's taken me so long to look at this.

@Arcterus Arcterus merged commit ab25919 into uutils:master Oct 1, 2017
@Matt8898
Copy link
Contributor Author

Matt8898 commented Oct 1, 2017

No problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants