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

Glob code refactoring #2137

Merged
merged 6 commits into from
Aug 18, 2022
Merged

Conversation

dmnks
Copy link
Contributor

@dmnks dmnks commented Aug 2, 2022

Clean up some old cruft, update the docs and prepare ground for the following PR.

@dmnks dmnks marked this pull request as draft August 2, 2022 10:06
@dmnks
Copy link
Contributor Author

dmnks commented Aug 2, 2022

Depends on #2151 so marking this one as a draft until it's merged.

@dmnks dmnks changed the title Glob code refactoring Glob code refactoring vol. 1 Aug 2, 2022
@dmnks dmnks force-pushed the iss1749-refactor branch from db77938 to 0286967 Compare August 8, 2022 16:24
@dmnks dmnks force-pushed the iss1749-refactor branch from 0286967 to e86c6f6 Compare August 16, 2022 08:48
@dmnks dmnks changed the title Glob code refactoring vol. 1 Glob code refactoring Aug 16, 2022
@dmnks dmnks force-pushed the iss1749-refactor branch from e86c6f6 to 73e6432 Compare August 17, 2022 08:23
Instead of constructing a new list from scratch and returning that, just
extend the passed list.  This makes it easier to use this function
incrementally when expanding multiple patterns in a loop, such as during
package manifest parsing which we adapt here right away.

Preserve the ability to pass NULL as argvPtr and still get a match count
via argcPtr, by keeping the local argv around for that case.

No functional change.
@dmnks dmnks force-pushed the iss1749-refactor branch from 73e6432 to 6e1279b Compare August 17, 2022 14:44
@dmnks
Copy link
Contributor Author

dmnks commented Aug 17, 2022

Rebased, ready for review now.

@dmnks dmnks marked this pull request as ready for review August 17, 2022 14:45
@dmnks dmnks linked an issue Aug 17, 2022 that may be closed by this pull request
dmnks added 5 commits August 17, 2022 17:33
By definition, glob(3) matches pathnames on the file system, so no
pattern starting with a URL protocol (e.g. http:// or file://) will ever
produce any meaningful results when passed to it, it will just fail with
GLOB_NOMATCH.

This wasn't always the case, we used to call a custom Glob() function
here in the past, which knew how to handle URLs, but that was axed in
commit 9cbf034 some 15 years ago.

To this day, however, we somewhat continue the legacy by letting
URL_IS_PATH (file://) patterns pass through glob(3) if they contain
magic chars, with the only possible outcome of failing afterwards.  Drop
this special case and simply consider any known URL pattern as non-local
(int local = 0) and return it immediately.  Also remove the no-op URL
code while at it.
Rather than listing all the rules, just refer the reader to the man
page.  Although brace expansion isn't part of the standard rules, we
still support it through glob(3) with GLOB_BRACE, so make a note.
Do set *argcPtr even if the actual count is 0, rather than leaving it
unchanged and thus possibly undefined in the caller.  This is also
consistent with how glob(3) works.
As per GNU glob(3), GLOB_ONLYDIR does not guarantee the matches are in
fact directories, that's why we check them with lstat(2).

That may lead to the match list being empty even after a successful
glob() run (rc == 0), so for consistency, return GLOB_NOMATCH in that
case, just like we would for a missing file.

No functional change since we don't check for the exact return code in
the callers, only whether it's positive or not.
No functional change, just shuffle some lines around for better
readability.
@pmatilai
Copy link
Member

Nice set of cleanups!

@pmatilai pmatilai merged commit f183ad4 into rpm-software-management:master Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants