bugGNU Octave - Bugs: bug #39684, WHAT function lists wrong directory

 
 

bug #39684: WHAT function lists wrong directory

Submitter:  None
Submitted:  Sat 03 Aug 2013 10:33:55 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Ben Kurtz Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.6.1
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 16 Dec 2013 05:40:00 PM UTC, comment #5: 

Thanks for following up, closing report as requested.

Mike Miller <mtmiller>
Group Member
Sun 15 Dec 2013 11:51:16 PM UTC, comment #4: 

The primary focus of this bug seems to have been fixed in revision 18060 (http://hg.savannah.gnu.org/hgweb/octave/rev/427412d40f1a).

the "returning multiple results" issue remains unfixed, but since it is mostly separate, I filed a new bug, #40904 (https://savannah.gnu.org/bugs/index.php?40904), with a patch for that, and this bug should be closed as fixed (which I can't seem to figure out how to do?).

Ben Kurtz <bkurtz>
Tue 06 Aug 2013 11:28:07 PM UTC, comment #3: 

I'm actually working on the classdef branch in the hg repo.  But according to

hg diff -r classdef -r default scripts/miscellaneous/what.m

the 'what' script hasn't been changed between those, and that's all the patch touches.

I suppose for reliability, I should also actually build the 'default' branch and confirm that it works there too... and sure enough, it does.

Anonymous
Sun 04 Aug 2013 08:06:18 PM UTC, comment #2: 

Confirmed, I also see odd behavior with the development version of Octave. I haven't had time to look at your patch yet, would you be able to make sure it applies cleanly and works with the development version instead of 3.6.1?

Mike Miller <mtmiller>
Group Member
Sat 03 Aug 2013 11:55:05 PM UTC, comment #1: 

Oops, I think I mixed up pathsep and filesep in a couple of places in my original submission.  Also upon further thinking, it looks like the implementation I proposed originally is not quite correct either.  However, I'm attaching a patch that I think is pretty close to correct.  Sorry if I didn't follow all the coding guidelines perfectly; I'm new to this.

Matlab's implementation is still slightly different (it doesn't actually call error() when no matches are found), but I'm less concerned about that than the core functionality.

(file #28752)

Anonymous
Sat 03 Aug 2013 10:33:55 PM UTC, original submission:  

The "what" function is documented as

w = what (DIR)
     List the Octave specific files in directory DIR


However, the test in the code doesn't actually behave this way.  Specifically, the code uses strfind without any backup checks, such that you can get things like the result below, where the input to what() doesn't match the directory looked up, or even any whole directory name.


octave:3> x = what('o')
x =

  scalar structure containing the fields:

    path = /usr/local/Cellar/octave/3.6.1/share/octave/3.6.1/m/time
    m =
    {
      [1,1] = addtodate.m
      [1,2] = asctime.m
      [1,3] = calendar.m
      [1,4] = clock.m
      [1,5] = ctime.m
      [1,6] = date.m
      [1,7] = datenum.m
      [1,8] = datestr.m
      [1,9] = datetick.m
      [1,10] = datevec.m
      [1,11] = eomday.m
      [1,12] = etime.m
      [1,13] = is_leap_year.m
      [1,14] = now.m
      [1,15] = weekday.m
    }
    mex = {}(0x1)
    oct = {}(0x1)
    mat = {}(0x1)
    mdl = {}(0x1)
    p = {}(0x1)
    classes = {}(0x1)


This leads to very frustrating results if I want to use what to look up the contents of any directory that has subdirectories, or any directory that happens to match any part of the path to the octave root.

The current implementation does one of two things for matching the directory name:
1. if the input DIR does not contain pathsep(), returns the last item on the user's path that matches DIR, irrespective of where that pathname matches
2. otherwise interpret DIR as being relative to the current working directory, and error if it does not exist.

This is incorrect in between 1 and 3 ways depending on how well you want to match MATLAB's behavior:
1. DIR should match the name of the directory being looked up, not earlier in the path, i.e. it should be anchored at the end of the path being matched, and should not be allowed to match partial directory names
2. DIR should be able to match locations in the user's path, even if it contains pathsep; conversely, even if DIR doesn't contain pathsep, it should match a subdirectory of the current working directory.
3. If multiple directories match, info about all of them should be returned, rather than the last one.

I'm thinking the implementation would be something like:
1. construct a list of all directories in the path and all directories in the current directory.
2. split each item in your list on pathsep(). similarly, split DIR on pathsep().
3. say the split form of DIR contains N items.  remove all but the last N items from all fields in your list
4. call isequal on each item in the list vs the split form of DIR to find the ones that match
5. support returning info for multiple directories

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #28752:  what.patch added by None (4KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  •  

    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 group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-12-16 mtmiller StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2013-08-04 mtmiller StatusNone Patch Submitted
    2013-08-03 None Attached File- Added what.patch, #28752

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code