git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH 3/6] dir-iterator: refactor dir_iterator_advance()

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Apr 11, 2022, 13:40 UTC
Message-ID
<9e5495d0-c117-2242-6718-46042e9664bf@gmail.com>
In-Reply-To
<220411.86o817j2dt.gmgdl@evledraar.gmail.com>
On 11/04/2022 12:11, Ævar Arnfjörð Bjarmason wrote:
Show 24 quoted lines
> 
> On Sun, Apr 10 2022, Plato Kiorpelidis wrote:
> 
>> +
>> +	errno = 0;
>> +	dir_entry = readdir(level->dir);
>>   
>> -		strbuf_setlen(&iter->base.path, level->prefix_len);
>> -		errno = 0;
>> -		de = readdir(level->dir);
>> -
>> -		if (!de) {
>> -			if (errno) {
>> -				warning_errno("error reading directory '%s'",
>> -					      iter->base.path.buf);
>> -				if (iter->flags & DIR_ITERATOR_PEDANTIC)
>> -					goto error_out;
>> -			} else if (pop_level(iter) == 0) {
>> +	if (dir_entry == NULL) {
> 
> Don't compare against NULL, use !dir_entry.
> 
> Also: Manually resetting "errno" before isn't needed. It will be (re)set
> if readdir() returns NULL().
That's not what the man page says
     If the end of the directory stream is reached, NULL is returned 
     and errno is not changed.  If an error occurs, NULL is returned 
     and errno is set to indicate the error.  To distinguish end of 
     stream from an error, set errno to zero before calling readdir() 
     and then check the value of errno if NULL is returned. 
Best Wishes
Phillip
Previous: Ævar Arnfjörð BjarmasonNext: Plato Kiorpelidis
Message 8 of 22 in “[GSoC] iterate dirs before or after their contents”
  1. 0/6 [GSoC] iterate dirs before or after their contentsPlato Kiorpelidis, Apr 10, 2022
  2. 1/6 t0066: improve readablity of dir-iterator testsPlato Kiorpelidis, Apr 10, 2022
  3. Phillip WoodApr 11, 2022
  4. Plato KiorpelidisApr 24, 2022
  5. 2/6 t0066: better test coverage for dir-iteratorPlato Kiorpelidis, Apr 10, 2022
  6. 3/6 dir-iterator: refactor dir_iterator_advance()Plato Kiorpelidis, Apr 10, 2022
  7. Ævar Arnfjörð BjarmasonApr 11, 2022
  8. Phillip WoodApr 11, 2022
  9. Plato KiorpelidisApr 27, 2022
  10. Phillip WoodApr 11, 2022
  11. Plato KiorpelidisApr 27, 2022
  12. 5/6 t0066: remove redundant testsPlato Kiorpelidis, Apr 10, 2022
  13. Ævar Arnfjörð BjarmasonApr 11, 2022
  14. Plato KiorpelidisApr 27, 2022
  15. 4/6 dir-iterator: iterate dirs before or after their contentsPlato Kiorpelidis, Apr 10, 2022
  16. Phillip WoodApr 11, 2022
  17. Plato KiorpelidisApr 27, 2022
  18. 6/6 test-dir-iterator: handle EACCES errno by dir-iteratorPlato Kiorpelidis, Apr 10, 2022
  19. Ævar Arnfjörð BjarmasonApr 11, 2022
  20. Plato KiorpelidisApr 27, 2022
  21. Phillip WoodApr 11, 2022
  22. Plato KiorpelidisApr 19, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.