-
-
Notifications
You must be signed in to change notification settings - Fork 311
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 sysinfo::Groups
implementation
#1210
Conversation
@@ -3213,8 +3384,7 @@ impl User { | |||
/// ``` | |||
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)] | |||
pub struct Group { | |||
pub(crate) id: Gid, |
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.
Any reason for this change? Gid
is already generated based on the OS so what needed for a GroupInner
type to be created?
src/windows/users.rs
Outdated
name: to_str(entry.lgrui0_name), | ||
id: Gid(0), | ||
inner: GroupInner { | ||
gid: Gid(0), |
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.
That's the main reason why I didn't provide a Group
API: Windows gid
is pointless, making the API kinda useless and incoherent on this platform.
It's a great start, thanks! I have a few questions and also an annoying blocker: this new API is currently not useable as is on Windows ( |
|
It's available on android but: #if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE
/* Android has thousands and thousands of ids to iterate through */
struct group* getgrent(void) __attribute__((warning("getgrent is inefficient on Android")));
void setgrent(void);
void endgrent(void);
int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
int getgrnam_r(const char *, struct group *, char *, size_t, struct group **);
#endif So I suppose the current approach is ok. Also, it's |
I checked a bit further and it's discouraged to use About I see you also removed the helpers on So with this, I think it'll be complete. Sorry again for the back and forth. ^^' |
src/common.rs
Outdated
@@ -3190,9 +3330,15 @@ impl User { | |||
} | |||
} | |||
|
|||
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)] | |||
pub(crate) struct BaseGroupInner { |
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.
Is not possible to declare GroupInner
here and to implement in the sub modules?
…pInner` in `sys`
Code implementation looks good! Just one thing missing: a test. Can you add a test checking that #[test]
fn test_groups() {
if !crate::IS_SUPPORTED_SYSTEM {
return;
}
assert!(!Groups::new_with_refresh_list().is_empty());
} |
Unit tests added. |
Great work, thanks a lot! |
This PR tries to implement #1198. It contains:
sysinfo::Groups
sysinfo::Group
's internal structure is changed to have aGroupInner
.users
modules, in order to adapt the structure change.When trying to implement the feature, I found on Windows,
gid
is always recognized as0
, but a SID is available. This PR didn't change Windows GID to SID as it may break public interface.