bugfindutils - Bugs: bug #54262, -printf %Y doesn't output N for...

 
 

bug #54262: -printf %Y doesn't output N for broken links

Submitted by:  Tavian Barnes <tavianator>
Submitted on:  Sat 07 Jul 2018 06:54:23 PM UTC  
 
Category:  locate Severity:  3 - Normal
Item Group:  Wrong result Status:  Fixed
Privacy:  Public Assigned to:  Bernhard Voelker <berny>
Originator Name:  Open/Closed:  Open
Release:  4.6.0 Fixed Release:  None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 26 Jul 2018 06:13:17 AM UTC, comment #5:

Pushed, thus marking this as fixed.

Bernhard Voelker <berny>
Project AdministratorIn charge of this item.
Tue 24 Jul 2018 07:02:22 AM UTC, comment #4:

good point - the attached fixes this.

(file #44610)

Bernhard Voelker <berny>
Project AdministratorIn charge of this item.
Fri 20 Jul 2018 04:18:20 PM UTC, comment #3:

Better:

$ ln -s nowhere broken
$ ln -s find/find/find notdir
$ find broken notdir -printf '%p %Y\n'
broken l
notdir l
$ ./find/find broken notdir -printf '%p %Y\n'
broken N
notdir ?./find/find: ‘notdir’: Not a directory

I think ENOTDIR should probably be treated the same as ENOENT.

Tavian Barnes <tavianator>
Fri 20 Jul 2018 02:54:26 PM UTC, comment #2:

Thanks for the report.
Please try the attached patchset [0/3].

(file #44602)

Bernhard Voelker <berny>
Project AdministratorIn charge of this item.
Sat 07 Jul 2018 07:26:07 PM UTC, comment #1:

The code in print.c is

/* If we would normally follow links, do not do so.
* If we would normally not follow links, do so.
*/
if ((following_links () ? optionp_stat : optionl_stat)
(state.rel_pathname, &sbuf) != 0)

which calls optionl_stat() in the default -P mode. But optionl_stat() calls fallback_stat() if the initial fstatat() fails, which does

switch (errno)
{
case ENOENT:
case ENOTDIR:
if (options.debug_options & DebugStat)
fprintf(stderr, "fallback_stat(): stat(%s) failed; falling back on lstat()\n", name);
return fstatat(state.cwd_dir_fd, name, p, AT_SYMLINK_NOFOLLOW);

which is probably wrong for %Y. Also the print.c code should probably check for ENOTDIR in addition to ENOENT.

Furthermore, the "if we would normally follow links, do not do so" comment, and subsequent attempt to use optionp_stat() if following_links(), seems to contradict the documentation which just says "(like %y), plus follow symlinks". But that whole block is guarded by

if (S_ISLNK (stat_buf->st_mode))

which won't be true except for broken links if following_links().

Tavian Barnes <tavianator>
Sat 07 Jul 2018 06:54:23 PM UTC, original submission:

man find says that -printf supports this format specifier:

%Y File's type (like %y), plus follow symlinks: L=loop, N=nonexistent

but

$ ln -s nonexistent broken
$ find broken -printf '%p %y %Y\n'
broken l l

The man page seems to imply that that should have been

broken l N

instead.

Tavian Barnes <tavianator>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #44610:  0001-find-printf-Y-handle-ENOTDIR-also-as-broken-symlink.patch added by berny (3KiB - text/x-patch - follow-up: [PATCH] find -printf %Y: handle ENOTDIR also as broken symlink)
file #44602:  bug-54262.patch added by berny (7KiB - text/x-patch - [PATCH 0/3] fixes regarding find -printf %Y)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by berny (Updated the item)
  • -email is unavailable- added by tavianator (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-07-26 berny StatusConfirmed => Fixed
    2018-07-24 berny Attached File- => Added 0001-find-printf-Y-handle-ENOTDIR-also-as-broken-symlink.patch, #44610
    2018-07-20 berny Attached File- => Added bug-54262.patch, #44602
        StatusNone => Confirmed
        Assigned toNone => berny

    Back to the top


    Powered by Savane 3.3