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

 
 

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

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

Add a New Comment Rich Markup
   

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

Pushed, thus marking this as fixed.

Bernhard Voelker <berny>
Group administrator
Tue 24 Jul 2018 07:02:22 AM UTC, comment #4: 

good point - the attached fixes this.

(file #44610)

Bernhard Voelker <berny>
Group administrator
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>
Group administrator
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 jay (Updated the item)
  • -email is unavailable- added by berny (Updated the item)
  • -email is unavailable- added by tavianator (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-08-29 jay Open/ClosedOpen Closed
    2019-08-29 berny Fixed ReleaseNone 4.7.0
    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.13-f8d8.
    Corresponding source code