bugGNU Octave - Bugs: bug #67018, glob doesn't match files when...

 
 

bug #67018: glob doesn't match files when match would be a single result

Submitter:  John Donoghue <lostbard>
Submitted:  Sun 13 Apr 2025 12:19:50 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  lostbard Open/Closed:  * Closed
Release:  * 9.1.0 Release: 
Operating System:  * GNU/Linux Fixed Release:  10.2.0 (current stable)
Planned Release:  10.2.0 (current stable)
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 16 Apr 2025 04:10:43 PM UTC, comment #9: 

Verified fix, closing report.

Rik <rik5>
Group administrator
Tue 15 Apr 2025 05:31:42 PM UTC, comment #8: 

I pushed the proposed change to the stable branch:
https://hg.savannah.gnu.org/hgweb/octave/rev/5df3822526c5

Thanks for the reminder, Rik.

Marking as ready for test.

Markus Mützel <mmuetzel>
Group administrator
Mon 14 Apr 2025 04:34:43 PM UTC, comment #7: 

glob() isn't a Matlab function, although there are File Exchange functions that people have written to get this functionality.  I see in 2023b that Matlab added a Glob class, but it only handles asterisk wildcards, and not other shell expressions such as '?' or '[]'.

Since this function is supposed to mimic what a shell glob expansion would do, I think we should look at what shells do.  For both bash and tcsh, there is no restriction to ordinary files.  The return results are based on whether the filename matches the pattern and whether it exists, but not on whether it is a block special device, character special device, etc.

I think the small modification from Markus in comment #6 should be applied.

Rik <rik5>
Group administrator
Mon 14 Apr 2025 07:49:20 AM UTC, comment #6: 

That is probably a regression from https://hg.savannah.gnu.org/hgweb/octave/rev/632f9b828de1

We could either make a change like proposed in comment #4 (and also allow fifo, link, and sock). Or if we care to distinguish regular files, we could add another argument (e.g., `is_any` defaulting to false) to `octave::sys::file_exist` and make it check `fs.exists ()`.

Or (maybe the cleanest?):

-  return (fs && (fs.is_reg () || (is_dir && fs.is_dir ())));
+  return (fs && (is_dir || ! fs.is_dir ()));


Markus Mützel <mmuetzel>
Group administrator
Sun 13 Apr 2025 02:48:48 AM UTC, comment #5: 

An alternative is to use POSIX "access()" instead of file_exist.
Not sure which one is better.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sun 13 Apr 2025 02:39:49 AM UTC, comment #4: 

I guess we could just change (in file_exist):


-  return (fs && (fs.is_reg () || (is_dir && fs.is_dir ())));
+  return (fs && (fs.is_reg () || fs.is_chr () || fs.is_blk () || (is_dir && fs.is_dir ())));


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sun 13 Apr 2025 02:27:03 AM UTC, comment #3: 

I think the problem is in "sys::file_exist". There is a "FIXME"

// FIXME: we shouldn't have to check to see if
              // a single match exists, but it seems that glob() won't
              // check for us unless the pattern contains globbing
              // characters.  Hmm.


And "file_exist" reject special files.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sun 13 Apr 2025 01:31:34 AM UTC, comment #2: 

Confirm with octave 11:

octave:14> glob("/dev/ttyS0*")
ans = {}(0x0)
octave:15> glob("/dev/ttyS1*")
ans =
{
  [1,1] = /dev/ttyS1
  [2,1] = /dev/ttyS10
  [3,1] = /dev/ttyS11
  [4,1] = /dev/ttyS12
  [5,1] = /dev/ttyS13
  [6,1] = /dev/ttyS14
  [7,1] = /dev/ttyS15
  [8,1] = /dev/ttyS16
  [9,1] = /dev/ttyS17
  [10,1] = /dev/ttyS18
  [11,1] = /dev/ttyS19
}


But it seems to work with 'normal" files:

octave:16> ls
a.out  check_getgrent.cc
octave:17> glob("a*")
ans =
{
  [1,1] = a.out
}

octave:18> glob("./a*")
ans =
{
  [1,1] = ./a.out
}

octave:19> glob("./a.out*")
ans =
{
  [1,1] = ./a.out
}


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sun 13 Apr 2025 12:36:30 AM UTC, comment #1: 

I executed the same test with an ordinary file in a directory that I have RW access to and it works.  You might try the same test just to make sure.

My guess is that there may be something special about the files (the ones you are trying to glob are character devices in Linux rather than ordinary files).

I can confirm that glob() works for 1-item lists in Octave 8.4, and returns nothing in Octave 9.1.  So that is where the problem entered.

Rik <rik5>
Group administrator
Sun 13 Apr 2025 12:19:50 AM UTC, original submission:  

Or perhaps some other reason ?


octave:9> ls -h /dev/ttyA*
/dev/ttyACM0
octave:10> glob("/dev/ttyA*")
ans = {}(0x0)


If I try in octave 8 It works fine



octave:2> ls -h /dev/ttyA*
/dev/ttyACM0
octave:3> glob("/dev/ttyA*")
ans =
{
  [1,1] = /dev/ttyACM0
}



Trying glob("/dev/tty*") appears to work in both - where more than one result would happen?

John Donoghue <lostbard>
Group Member

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

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 dasergatskov (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by lostbard (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 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-04-16 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 10.2.0 (current stable)
    2025-04-15 mmuetzel StatusIn Progress Ready For Test
    2025-04-14 rik5 StatusConfirmed In Progress
    2025-04-14 mmuetzel Releasedev 9.1.0
        Fixed Release10.2.0 (current stable) None
        Planned ReleaseNone 10.2.0 (current stable)
    2025-04-13 rik5 StatusNone Confirmed
        Summaryglob doesnt match files when match would be a single result glob doesn't match files when match would be a single result

    Back to the top

    Powered by Savane 3.14-962f.
    Corresponding source code