Pádraig Brady <[email protected]> writes: > On 21/11/2026 00:09, Collin Funk wrote: >> Pádraig Brady <[email protected]> writes: >> >>> On 20/11/2026 21:39, Collin Funk wrote: >>>> I was looking at this one a bit yesterday (didn't have anything close to >>>> a patch being finished, so don't worry about that), and wanted to see if >>>> FTS_NOSTAT could be used to avoid stat'ing twice where O_PATH is >>>> available. I guess it doesn't matter too much in practice. It is a >>>> larger refactoring that can probably just be done later. >>> >>> Oh good point. I'll have a look at that optimization. >> NP. My thinking was to enable FTS_NOSTAT always, and then just >> handle >> the stat in adjust_file_mode(). Perhaps it is just me, but I find that >> conditionally using FTS_NOSTAT as src/chown-core.c does require a bit >> more careful thought. >> FTS_NOSTAT still does stat command-line arguments, though. I was >> conflicted about whether it was worth handling the FTS_ROOTLEVEL case or >> not, to avoid stat. > > I've done the FTS_NOSTAT in the attached. > It's worth doing as it halves the stats, > and is very little code and mostly comments. > The tricky bit was to do with symlink handling.
[...] > + /* Adjust so a symlink identified by readdir > + or by FTS' stat() are handled consistently. */ > + int fts_info = ent->fts_info; > + if (fts_info == FTS_NSOK && S_ISLNK (file_stats->st_mode)) > + fts_info = FTS_SL; > + bool ignore_missing = fts_info != FTS_SL && ignore_missing_fts_entry (ent); Ah nice. That is far fewer lines of code than my idea. I think I overthought this part. For some reason, I mistakenly remembered FTS_NOSTAT as being far more aggressive than it is. My concern was that st_mode would be zeroed out on platforms without d_type. But I see now that it uses stat in that case to check whether it is a directory. >>> Well I only did a quick search on FreeBSD and it seems >>> these are available since 13.1 (2022), but I have not tested there. >>> I will test there and make the NEWS less Linux specific. >> True, I am probably just splitting hairs. 2022 is relatively new. >> The >> 'shred' races, e.g., were also because the program was written before >> openat existed. I felt less bad about calling those bugs since we were a >> bit later in that case. :) > > Oh I see what you're saying. > Given this is quite an edge case problem, > and this avoidance is only possible with kernel/libc > features available relatively recently > (glibc >= 2.39 (2024) on Kernel >= 6.6 (2023), or FreeBSD >= 13.1 (2022)) > then it could be classed as an improvement rather than a bug fix. > > I'll clarify version details in NEWS anyway. Yep, exactly. > BTW I've just tested on FreeBSD 14.1 and all tests pass > (and the new code was used there). Nice catch on patch 3, which I guess matters on BSD mostly since they allow changing permissions on symlinks. Collin
