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


bug #39684: WHAT function lists wrong directory

Submitted by:  None
Submitted on:  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

Add a New Comment(Rich Markup)

You are not logged in

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


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

Thanks for following up, closing report as requested.

Mike Miller <mtmiller>
Project Administrator
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
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.

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>
Project Administrator
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)

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

The "what" function is documented as

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.

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



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

Attach Files:

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)

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


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    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.3