bugGNU Octave - Bugs: bug #56267, addpath() on Windows fails to...


bug #56267: addpath() on Windows fails to recognize same subdirs with different fileseps and case

Submitted by:  Philip Nienhuis <philipnienhuis>
Submitted on:  Sun 05 May 2019 08:41:43 AM UTC  
Category:  Octave Function Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Philip Nienhuis Open/Closed:  Open
Release:  dev Operating System:  Microsoft Windows

Add a New Comment (Rich Markup)

You are not logged in

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


( Jump to the original submission)

Thu 09 May 2019 07:18:38 PM UTC, comment #7: 

Enjoy your, I hope, vacation.  Can take this up later.

Rik <rik5>
Project Administrator
Thu 09 May 2019 07:09:09 PM UTC, comment #6: 

if you look at what javaaddpath does in comment #2 it turns out it does the right thing. It checks with the OS or the exact case.
Whether there are other checks that make sure the file name matches I don't know.

Anyway I'm out for  week.

Philip Nienhuis <philipnienhuis>
Project Member
Thu 09 May 2019 05:51:25 PM UTC, comment #5: 

If it does a verbatim copy then canonicalize_file_name handles only the file separator part of the duplication.  But it would still be possible to add two equivalent directory with different cases

addpath ('C:\USERS')
addpath ('C:\Users')

Rik <rik5>
Project Administrator
Thu 09 May 2019 05:39:35 PM UTC, comment #4: 

> What does this return on Windows?

(Didn't try, no time, I'll be away for a week.)

But see comment #2, 2nd verbatim block. It does the right thing, i.e., verbatim copy the actual path including the right case.

Philip Nienhuis <philipnienhuis>
Project Member
Thu 09 May 2019 05:31:40 PM UTC, comment #3: 

I checked on the code in javaclasspath.m and it is:

for i = 1:numel (varargin)
  clspath = varargin{i};
  if (! ischar (clspath))
    error ("javaaddpath: CLSPATH must be a string");

  new_path = canonicalize_file_name (tilde_expand (clspath));
  if (isfolder (new_path))
    if (new_path(end) != filesep ())
      new_path = [new_path, filesep()];
  elseif (! exist (new_path, "file"))
    error ("javaaddpath: CLSPATH does not exist: %s", clspath);

  success = javaMethod ("addClassPath", "org.octave.ClassHelper", new_path);

So, just as suspected, it calls canonicalize_file_name to make the name standard before adding it to the path, and that standardization eliminates the duplicates that differ by file separator.

Does canonicalize_file_name also handle case?

What does this return on Windows?

canonicalize_file_name ('C:\USERS\PHILIP')

Rik <rik5>
Project Administrator
Tue 07 May 2019 06:15:17 AM UTC, comment #2: 

Thanks for picking up, Rik.

>> canonicalize_file_name ('C:/Users/Philip')
ans = C:\Users\Philip
>> canonicalize_file_name ('C:\Users\Philip')
ans = C:\Users\Philip

What matters here is simply consistent fileseps and ignoring casing.
I checked with javaaddpath: that is doing the exact right thing:

GNU Octave, version 6.0.0
>> javaclasspath

      - empty -


>> javaaddpath('C:/Users/Philip/java/poi-4.0.0.jar')
>> javaclasspath

      - empty -



so there we have example code that can be mimicked.

Philip Nienhuis <philipnienhuis>
Project Member
Mon 06 May 2019 10:35:37 PM UTC, comment #1: 

In Octave, what does this return?

canonicalize_file_name ('C:/Users/Philip')
canonicalize_file_name ('C:\Users\Philip')

If they return the same string then we could add a call to canonicalize_file_name in addpath before checking whether a path is a duplicate.

Rik <rik5>
Project Administrator
Sun 05 May 2019 08:41:43 AM UTC, original submission:  

AFAIK addpath() normally recognizes if its argument is already in the PATH and if so, doesn't add it to the PATH a second time.
But on Windows, where both '\' and '/' are accepted as file separators and path-/filenames are case-insensitive, it gets confused by different fileseps and different case in otherwise identical arguments, so the PATH can end up as follows:

>> path

Octave's search path contains the following directories:


Of course it's no big deal, Octave works fine anyway, but it is unneeded cluttering of the search path.

Severity => Minor

Philip Nienhuis <philipnienhuis>
Project Member


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

Attach Files:

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 rik5 (Posted a comment)
  • -email is unavailable- added by philipnienhuis (Submitted the item)

    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.




    No changes have been made to this item

    Back to the top

    Powered by Savane 3.5