Skip to content

Conversation

@jakub-nt
Copy link
Contributor

@jakub-nt jakub-nt commented Apr 9, 2025

No description provided.

…path

Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
@jakub-nt jakub-nt requested a review from olehermanse April 9, 2025 15:49
Comment on lines +38 to +40
def name(path):
"""Returns the name of the path to file or directory."""
return path_components(path)[-1]
Copy link
Member

Choose a reason for hiding this comment

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

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("..")
Copy link
Member

Choose a reason for hiding this comment

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

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

@olehermanse olehermanse merged commit 39fbb85 into cfengine:master Apr 10, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants