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

New transformer: basename() #1927

Closed
Tracked by #3255
leogr opened this issue Jun 20, 2024 · 3 comments · Fixed by #1943
Closed
Tracked by #3255

New transformer: basename() #1927

leogr opened this issue Jun 20, 2024 · 3 comments · Fixed by #1943
Assignees
Labels
kind/feature New feature or request

Comments

@leogr
Copy link
Member

leogr commented Jun 20, 2024

Motivation

The basename() transformer will make it easier for rule authors to write concise and effective rules, particularly for fields returning a full path by extracting the base name from a field returning a full path.

Note that this is particularly useful in conjunction with proc.exepath which provides the resolved symlink path eventually, since proc.exe can't provide the resolved path because it, by convention, equals to argv[0].

Feature

Introduce the basename(<path>) transformer that works similarly to the basename util.

This transformer returns the base name of a given <path> (i.e. a string) as an argument.

Alternatives

No compelling alternatives. For the record, some discarded solutions:

  1. changing proc.exe (breaking change + inconsistency)
  2. adding new fields (eg. proc.exepath.basename) comes with too many cons:
    • redundant with fields modifiers (ie. basename())
    • would require similar fields for proc.pexepath and proc.aexepath, increasing complexity
    • the solution is not reusable

Additional context

cc @darryk10 @loresuso

@loresuso
Copy link
Member

I fully support this feature request!

Just the first thing that comes to mind, introducing basename would also probably conflict with fd.filename, that is basename(fd.name) would be totally the same thing as fd.filename. We would probably need a deprecation plan for that field or other similar ones if any.

@leogr
Copy link
Member Author

leogr commented Jun 24, 2024

fd.filename. We would probably need a deprecation plan for that field or other similar ones if any.

Totally 👍

@LucaGuerra
Copy link
Contributor

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants