Re: [PATCH v5 9/9] dir: introduce readdir_skip_dot_and_dotdot() helper
- From
Derrick Stolee <stolee@gmail.com>
- Date
- May 17, 2021, 17:22 UTC
- Message-ID
- <2b7ba27c-5ffa-0ef0-6c7a-4da45f979b9c@gmail.com>
- In-Reply-To
- <b7c6176560bda67e146d0402f927180dace534a2.1620840502.git.gitgitgadget@gmail.com>
On 5/12/2021 1:28 PM, Elijah Newren via GitGitGadget wrote:
Show 20 quoted lines
> From: Elijah Newren <newren@gmail.com>
>
> Many places in the code were doing
> while ((d = readdir(dir)) != NULL) {
> if (is_dot_or_dotdot(d->d_name))
> continue;
> ...process d...
> }
> Introduce a readdir_skip_dot_and_dotdot() helper to make that a one-liner:
> while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {
> ...process d...
> }
>
> This helper particularly simplifies checks for empty directories.
>
> Also use this helper in read_cached_dir() so that our statistics are
> consistent across platforms. (In other words, read_cached_dir() should
> have been using is_dot_or_dotdot() and skipping such entries, but did
> not and left it to treat_path() to detect and mark such entries as
> path_none.)I like the idea of this helper!
> +struct dirent * > +readdir_skip_dot_and_dotdot(DIR *dirp)
nit: This seems like an accidental newline between the return type and the method name.
Otherwise, patch LGTM.
-Stolee