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

add unistd::getcwd and unistd::mkdir #416

Merged
merged 9 commits into from
Sep 7, 2016
Merged

Conversation

philippkeller
Copy link

As a (late) followup of this withdrawn PR I have added getcwd (wrapper around libc::getcwd) and mkdir (wrapper around libc::mkdir) and added testing.

A few notes:

  • I'm new to rust so I would appreciate some pair of eyes testing the code, plus I'm open for revision of code or general remarks about my coding style
  • I have run the tests both on OSX as on Linux (Ubuntu)
  • I've run clippy to see if my code is well formatted, however clippy issues many warnings about the project. I think I didn't add any more warnings
  • the methods in unistd are not documented so I also left out the documentation of getcwd and mkdir, although I think it'd probably be good to add some documentation, especially some example code how to use the methods
  • the base idea of getcwd is taken from std, should I mention that somewhere?

Philipp Keller added 3 commits September 2, 2016 22:57
…to expect into proper try handling), needs testing still
… directory names, need to be created with mkdir first which doesn't exist yet)
@philippkeller
Copy link
Author

oh, failing tests for Rust 1.2, I'll check the errors in a few hours

@posborne
Copy link
Member

posborne commented Sep 6, 2016

oh, failing tests for Rust 1.2, I'll check the errors in a few hours

Looks like the errors should be pretty easy to resolve. At some point, I think we're OK with dropping 1.2 but in this case, it should be pretty easy to satisfy the compiler.

@philippkeller
Copy link
Author

@posborne indeed, I'm almost there. I ended up with an exact copy of the implementation in std (which I somehow was not able to make running but found out that I needed to add use std::os::unix::ffi::OsStringExt to bring the unix specific trait from_vec into scope)

// ERANGE means buffer was too small to store directory name
if error != Errno::ERANGE {
return Err(Error::Sys(error));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint. I've corrected those now. Any idea why cargo clippy did not warn about those?

"/private/tmp/"
} else {
"/tmp/"
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little fragile. I think it would be OK to just verify that the nix getcwd results match those of libstd without hardcoding absolute base paths which may change based on the OS and system (My tmpfs may not be at /tmp).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, I'll change this and add documentation for getcwd and mkdir

@posborne
Copy link
Member

posborne commented Sep 6, 2016

the methods in unistd are not documented so I also left out the documentation of getcwd and mkdir, although I think it'd probably be good to add some documentation, especially some example code how to use the methods

I would like to see the documentation of nix improve. We would welcome documentation (including examples) for new code.

@philippkeller
Copy link
Author

@posborne I fixed the test and added documentation for getcwd and mkdir. Can you have a look again?

use std::mem;
use std::ffi::CString;
use std::ffi::{CString,CStr,OsString};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spaces after comma.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

assert!(mkdir(tmp_dir.as_path(), stat::S_IRWXU).is_ok());
}
assert!(chdir(tmp_dir.as_path()).is_ok());
assert_eq!(getcwd().unwrap(), current_dir().unwrap());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that this code is indented with 2-spaces for some reason. Should be 4.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running rustfmt as a last step of preparing a PR should be added to our CONTRIBUTING.md.

@posborne
Copy link
Member

posborne commented Sep 7, 2016

@homu r+

@homu
Copy link
Contributor

homu commented Sep 7, 2016

📌 Commit 7dd12c6 has been approved by posborne

@homu
Copy link
Contributor

homu commented Sep 7, 2016

⚡ Test exempted - status

@homu homu merged commit 7dd12c6 into nix-rust:master Sep 7, 2016
homu added a commit that referenced this pull request Sep 7, 2016
add unistd::getcwd and unistd::mkdir

As a (late) followup of [this withdrawn PR](rust-lang/libc#326) I have added getcwd (wrapper around `libc::getcwd`) and mkdir (wrapper around `libc::mkdir`) and added testing.

A few notes:

 - I'm new to rust so I would appreciate some pair of eyes testing the code, plus I'm open for revision of code or general remarks about my coding style
 - I have run the tests both on OSX as on Linux (Ubuntu)
 - I've run `clippy` to see if my code is well formatted, however clippy issues many warnings about the project. I think I didn't add any more warnings
 - the methods in unistd are not documented so I also left out the documentation of `getcwd` and `mkdir`, although I think it'd probably be good to add some documentation, especially some example code how to use the methods
 - the base idea of `getcwd` is [taken from std](https://github.com/rust-lang/rust/blob/1.9.0/src/libstd/sys/unix/os.rs#L95-L119), should I mention that somewhere?
This was referenced Sep 7, 2016
@philippkeller
Copy link
Author

Yay, thanks a lot @posborne for the helpful comments and the merge. I'm feeling proud - that was my first bigger PR into a rust project

@fiveop
Copy link
Contributor

fiveop commented Sep 8, 2016

Thank you!

Could you add entries to the CHANGELOG.md detailing your changes? Preferably before we cut the release.

philippkeller pushed a commit to philippkeller/nix that referenced this pull request Sep 9, 2016
homu added a commit that referenced this pull request Sep 9, 2016
Update CHANGELOG for pull request 416

As [requested by @fiveop](#416 (comment))
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

4 participants