ENT-12739: Added detection of the user providing wrong policy set path in cfbs analyze#222
Merged
olehermanse merged 1 commit intocfengine:masterfrom Apr 10, 2025
Merged
Conversation
…path Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
olehermanse
approved these changes
Apr 10, 2025
Comment on lines
+38
to
+40
| def name(path): | ||
| """Returns the name of the path to file or directory.""" | ||
| return path_components(path)[-1] |
Member
There was a problem hiding this comment.
This is usually referred to as basename. Maybe use os.path.basename() instead, or if you need some slightly different behavior, make a wrapper called basename() which does what you want.
Comment on lines
+581
to
+586
| # for drive root, the path's parent is the path itself, so only check the parent path if this is not the case | ||
| if os.path.realpath(path) != os.path.realpath(os.path.join(path, "..")): | ||
| if os.path.exists(os.path.join(path, "..", "update.cf")) or os.path.exists( | ||
| os.path.join(path, "..", "promises.cf") | ||
| ): | ||
| possible_policyset_relpaths.append("..") |
Member
There was a problem hiding this comment.
drive root is the root of the filesystem, right?
This part is a bit cryptic, and could be more readable, I think, something like this;
Suggested change
| # for drive root, the path's parent is the path itself, so only check the parent path if this is not the case | |
| if os.path.realpath(path) != os.path.realpath(os.path.join(path, "..")): | |
| if os.path.exists(os.path.join(path, "..", "update.cf")) or os.path.exists( | |
| os.path.join(path, "..", "promises.cf") | |
| ): | |
| possible_policyset_relpaths.append("..") | |
| # for file system root, the path's parent is the path itself, so only check the parent path if this is not the case | |
| current = os.path.realpath(path) | |
| parent = os.path.realpath(os.path.join(path, "..")) | |
| at_root = (path == "/") # or current == parent | |
| if not at_root: | |
| if os.path.exists(os.path.join(parent, "update.cf")) or os.path.exists( | |
| os.path.join(parent, "promises.cf") | |
| ): | |
| possible_policyset_relpaths.append("..") |
That might even make the comment unnecessary (which is a good thing).
Also, importing the functions you need from os.path could help reduce noise;
from os.path import exists, realpath, join
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.