bugGNU Octave - Bugs: bug #62589, dir ('NAME*/') should list...

 
 

bug #62589: dir ('NAME*/') should list contents of directories rather than directory names

Submitter:  Patrick Häcker <magicmuscleman>
Submitted:  Mon 06 Jun 2022 03:20:27 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 15 Jun 2022 06:06:06 PM UTC, comment #7: 

The necessary changes are pretty straight forward when it comes to getting this more or less compatible if there is only one single matching directory (see attachment).
It'll need to get a little bit more involved if there are multiple matching directories...

(file #53306)

Markus Mützel <mmuetzel>
Group administrator
Mon 06 Jun 2022 09:25:34 PM UTC, comment #6: 

I think there is only one Matlab compatibility issue here which is the listing of contents when the directory name ends with a file separator.

Matlab, like Octave, does not list the contents of a directory which uses wildcard character in the name even if there is only one such directory.


mkdir ('my*dir')
dir ('my*dir')
my*dir


Rik <rik5>
Group administrator
Mon 06 Jun 2022 06:58:20 PM UTC, comment #5: 

Missing from the reproducer in comment #4:

octave:8> dir('s*')
s*        scripts   src       stamp-h1
octave:9> dir('s*/')


Markus Mützel <mmuetzel>
Group administrator
Mon 06 Jun 2022 06:52:15 PM UTC, comment #4: 

Reproducer in Octave's build tree:

$ mkdir 's*'
$ ./run-octave


octave:1> dir('s*')
s*        scripts   src       stamp-h1
octave:2> dir('s\*')
s*
octave:3> dir('s\*/')

octave:4> glob('s\*')
ans =
{
  [1,1] = s*
}

octave:5> glob('s\*/')
ans =
{
  [1,1] = s*/
}

octave:6> glob('s*')
ans =
{
  [1,1] = s*
  [2,1] = scripts
  [3,1] = src
  [4,1] = stamp-h1
}

octave:7> glob('s*/')
ans =
{
  [1,1] = s*/
  [2,1] = scripts/
  [3,1] = src/
}


Markus Mützel <mmuetzel>
Group administrator
Mon 06 Jun 2022 06:49:17 PM UTC, comment #3: 

IIUC, those are two different issues. (And I can confirm both also on Windows.)

The first is that the content of directories containing a literal asterisk `*` in their name cannot be listed with `dir`.

The second is that patterns containing the `*` wildcard that end in a file separator don't work.

Both seem to be an issue in `dir.m`. `glob` and `__wglob__` seem to handle these patterns correctly.

Markus Mützel <mmuetzel>
Group administrator
Mon 06 Jun 2022 06:17:15 PM UTC, comment #2: 

I've re-titled the report to what I think is the actual issue.  Octave has never behaved this way so it is not a regression, but rather just an incompatibility with Matlab.  I have changed the Item Group to "Matlab Compatibility" and changed the release to "dev".

I took a look at changing this and I got about halfway there, but then found that my approach wasn't going to work.  It seems the code is going to have to go into the main loop rather than just at the top where the variable 'flst' is initialized.

Rik <rik5>
Group administrator
Mon 06 Jun 2022 04:03:27 PM UTC, comment #1: 

Confirmed.  Trying to get exactly compatible behavior with Matlab is annoying.  For example, their documentation says that the asterisk character is always treated as a wildcard---even on UNIX-like systems where that could be a legitimate character in a filename.  Something like


dir ('\*a/')


is never going to work because the escape character doesn't actually escape anything.

From what I can decipher of Matlab behavior, when a wildcard is used (and an asterisk is the only wildcard for Matlab) it returns the directory name and not the director contents.  However, if a file separator is added after the wildcard then directory contents are returned.

Example code


mkdir ('*a')
dir ('*a')
*a

mkdir ('*ba')
dir ('*a')
*a    *ba

dir ('*a/')
Files found in: *a
.     ..

Files found in: *ba
.     ..



Rik <rik5>
Group administrator
Mon 06 Jun 2022 03:20:27 PM UTC, original submission:  

At least in GNU/Linux it's valid to have '*' in the file name.
This can be easily created on the shell:
~> mkdir '*a' b
In Octave using the dir function with a leading slash does not work when a wildcard is included in the directory name (it works for 'b', but not for '*a'):
octave:1> dir('b/')
.   ..
octave:2> dir('b')
.   ..
octave:3> dir('*a')
*a
octave:4> dir('*a/')
 
octave:5> dir('\*a/')

octave:6>

This worked in previous versions. I think it worked in 6.2.0. I haven't checked, but if I'd guess, I think trying to fix #58976 broke it.

Patrick Häcker <magicmuscleman>

 

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

Attach Files:
   
   
Comment:
   

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by magicmuscleman (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 group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-06-15 mmuetzel Attached File- Added bug62589-dir-wildcard.patch, #53306
    2022-06-06 mmuetzel Operating SystemGNU/Linux Any
    2022-06-06 rik5 Item GroupRegression Matlab Compatibility
        Release7.1.0 dev
        Summarydir does not work correctly with '*' in directory name in 7.1.0 dir ('NAME*/') should list contents of directories rather than directory names
    2022-06-06 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code