-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Implementation of chown, lchown and fchown for the os module #1984
Conversation
Up ? Is any seasoned contributor available to answer my questions and help me get this PR in a mergeable state ? :) |
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 I missed this :) Nice work!
vm/src/stdlib/os.rs
Outdated
let flag = match follow_symlinks.follow_symlinks { | ||
true => nix::unistd::FchownatFlags::FollowSymlink, | ||
false => nix::unistd::FchownatFlags::NoFollowSymlink, | ||
}; |
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.
This should fix the error in CI.
let flag = match follow_symlinks.follow_symlinks { | |
true => nix::unistd::FchownatFlags::FollowSymlink, | |
false => nix::unistd::FchownatFlags::NoFollowSymlink, | |
}; | |
let flag = if follow_symlinks.follow_symlinks { | |
nix::unistd::FchownatFlags::FollowSymlink | |
} else { | |
nix::unistd::FchownatFlags::NoFollowSymlink | |
}; |
|
Oh, and yeah, you can ignore the auditing events stuff. |
I fixed the clippy lint.
I also fixed this, thanks. Do you think it could be usefull to refactor this weird Option into a cleaner enum then ? Something like enum SupportStatus {
SUPPORTED,
TODO,
NOT_SUPPORTED,
} I"ll gladly open a PR for this if you think this is useful. |
Finally, I"d feel more confident if I wrote at least unit tests for this piece of code. I can write some rust tests on the rust function but I think that it misses the point and I"d rather write python tests where I actually call the function os.chown from python code (liek integration testing) |
Yeah, I think the 3-enum rather than the re: unit testing; there is a |
Ok the CPython tests are a nice resource indeed ! I"ll try to draw inspiration from these for sure, and maybe add a few more test cases. |
Regarding the issue I mentioned in my original comment regarding the tilde expansions, it seems that neither Rust nor Python do it, so I won"t add support for it. |
Ah, yeah, I think you have to manually opt in to that with |
09a693b
to
3071b00
Compare
Just wrote a first few tests (mostly copied from CPython test suite) and I have a few things to say:
Regarding the CI failing, it seems that with rust stable bumping to 1.45 today, clippy is now more restrictive on certain things and code that was previously considered correct is no longer. It should eventually be fixed in another PR. Regarding the sister functions of chown (lchown, fchown, ...), I will add them so please don"t close this PR now. Regarding the adding of an enum for SupportFuncs, I will move this to another PR to keep things clean. As I am a newcomer on this project and that PR got me to take a look around a few parts of it (namely the standard lib and the integration tests), I will write down my take on this "experience" and on the entry barrier to new contributors as I perceived it. The architecture of the Lib reimplementation could be improved by creating rust module for each library module and creating a single file for each function in this module. That way, code would be cleaner, it would reduce conflicts, it would allow us to write clean rust unit tests in each file to test only a function, without cluttering an already too large file. (eg the os file is already more than 2300 loc and we are far from having everything implemented) |
Yeah, the test snippets aren"t very well organized, partly because we don"t need them to be; the idea is that we just have a bunch of snippets that |
Also, the clippy lints should be fixed on master now. |
…or chown function
3071b00
to
428bf1e
Compare
I just added support for fd and sister functions fchown and lchown, I think that the PR is mergeable now. Let me know if there is anything to alter still. |
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 agree to SupportStatus
. For the snippets, it was historically important before we could run CPython unittests but not anymore like before. These days, we just need to cover a bit more there which is not covered by CPython unittests. I feel like adding note to related documentation is enough and there is not much reason to spend a lot of resources for the snippets test.
Hello all,
I am trying to implement the chown function for the os module (https://docs.python.org/3/library/os.html#os.chown), because of issue #1175 .
I am a new contributor and I"d like to have feedback on this first take at the implementation. It is not finished yet but I have a few questions and I wanted to be sure that I am going in the good direction.
As of now, the chown function works properly given that you invoke rustpython with root permissions. I can successfully change uid and gid of a file, or use -1 to preserve them. I am having a few issue with the path to file, it does not seem yet to accept unix shorthands like ~ (FileNotFound error, might come from nix lib, need to investigate).
I have not tested dir_fd and _follow_symlink yet since I am not sure how to handle these arguments with defaults values.
More particularly, in line 1988, I am not sure to understand how to initialise a new SupportFunc, what it actually is and why it takes Options on bool rather than bool. I took example on other functions and used false in the Options but I think it should be true since this function supports use of file descriptors and following symlinks, unless I did not understand properly what the bool means here.
I am planning on implementing lchown and fchown after this by using to this first chown function.
I am planning to write proper unit tests but I have no clue on how to write them and what you are expecting as proper tests.
Finally, in the python doc, it says that these functions raises AuditingEvents. I am not familiar with this, is it supported in rustpython yet ? Should I care about this ?
Thanks for your feedback