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

Process: namespaces: Change from Vec to HashMap #185

Merged
merged 1 commit into from
Jul 20, 2022

Conversation

arilou
Copy link
Contributor

@arilou arilou commented Jul 17, 2022

This change breaks the API for process namespaces, but it provides
a more efficient way of working with the namespaces of a process.

Signed-off-by: Jon Doron jond@wiz.io

@eminence
Copy link
Owner

LGTM, except for the small logic fix

@arilou
Copy link
Contributor Author

arilou commented Jul 18, 2022

Cool can you please tell me what would you like me to change? Which logic?

src/process/namespaces.rs Outdated Show resolved Hide resolved
@eminence
Copy link
Owner

Oops, sorry about that. I forgot to click the "submit review" button

@@ -39,8 +45,6 @@ impl Process {
/// See also the [Process::namespaces()] method
#[derive(Debug, Clone)]
pub struct Namespace {
/// Namespace type
pub ns_type: OsString,
Copy link
Owner

Choose a reason for hiding this comment

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

Also, for better compatibility, I'm inclined to keep the ns_type field. For people who are currently using the Vec<_> interface, including the ns_type in the struct is more useful, at the expense of a small amount of memory duplication

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem will do

Comment on lines 27 to 45
namespaces
.insert(
ns_type.clone(),
Namespace {
ns_type,
path,
identifier: stat.st_ino,
device_id: stat.st_dev,
},
)
.map_or_else(
|| Ok(()),
|n| {
Err(build_internal_error!(format!(
"NsType appears more than once {:?}",
n.ns_type
)))
},
)?;
Copy link
Owner

Choose a reason for hiding this comment

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

Sorry to be a pain about this, but I think this can be written much more cleanly by just using a simple if statement:

Suggested change
namespaces
.insert(
ns_type.clone(),
Namespace {
ns_type,
path,
identifier: stat.st_ino,
device_id: stat.st_dev,
},
)
.map_or_else(
|| Ok(()),
|n| {
Err(build_internal_error!(format!(
"NsType appears more than once {:?}",
n.ns_type
)))
},
)?;
if namespaces
.insert(
ns_type.clone(),
Namespace {
ns_type,
path,
identifier: stat.st_ino,
device_id: stat.st_dev,
},
)
.is_some()
{
return Err(build_internal_error!(format!("Duplicate namespace type {:?}", ns_type)));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, pushed a new revision, please let me know if there is any other change you would like to have.

This change breaks the API for process namespaces, but it provides
a more efficent way of working with the namespaces of a process.

Signed-off-by: Jon Doron <jond@wiz.io>
@eminence
Copy link
Owner

Thanks!

@eminence eminence merged commit 3f89ee2 into eminence:master Jul 20, 2022
@eminence
Copy link
Owner

This change has been published as version v0.14.0

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.

2 participants