bugGNU Octave - Bugs: bug #41978, hgload not finding correct *.ofig...

 
 

bug #41978: hgload not finding correct *.ofig file

Submitter:  Muhali <muhali>
Submitted:  Thu 27 Mar 2014 02:30:30 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 28 Mar 2014 05:02:38 PM UTC, comment #8: 

works for me now. Thanks.

Muhali <muhali>
Fri 28 Mar 2014 04:07:10 PM UTC, comment #7: 

@Rik: Thanks. I'm sorry, I should have updated before modifying. Nevertheless, I'm not sure that file_in_loadpath() is required anymore (of course, my patch was wrong in any case).

Massimiliano Fasi <mfasi>
Fri 28 Mar 2014 03:52:09 PM UTC, comment #6: 

I checked in a changeset that should fix this (http://hg.savannah.gnu.org/hgweb/octave/rev/348f67886dc4).  I'm marking the bug as "Ready For Test".

@Massimiliano, I based the change on the most current Mercurial sources rather than your patch because the sources had already shifted from using exist() to file_in_loadpath() to correct a different problem that Muhali found.

Rik <rik5>
Group administrator
Fri 28 Mar 2014 12:48:36 PM UTC, comment #5: 

I have submitted a patch that should fix the bug. It does not warn the user if he/she is using an extension that differs from ".ofig", but does not try to open file without extension. Thank you!

(file #31064)

Massimiliano Fasi <mfasi>
Fri 28 Mar 2014 12:32:11 PM UTC, comment #4: 

Hi,

first of all, I noticed that I was using the version I submitted, that turned out to be slightly different from the one that was committed. Indeed, I checked the file existence using a not-so-Octave way


  ## Check file extension and existence
  [dir, name, ext, ver] = fileparts (filename);
  if (strcmp (ext, ""))
    warning ("hgload: no extension given, trying with .ofig");
    filename = strcat(filename, ".ofig");
  elseif (!strcmp(ext, ".ofig"))
    warning ("hgload: file extension should be .ofig");
  endif


that did not suffer from this bug. I think that the new version is better, but I am a little bit suspicious about the fact that the existence of the file is checked twice in two nested if. I think that these two solutions can be merged and I'm trying to do it, I will update this thread soon (I hope).

Massimiliano Fasi <mfasi>
Fri 28 Mar 2014 09:33:56 AM UTC, comment #3: 

when you do


system("touch foo");
plot([1 2 3]);
hgsave("foo");
hgload("foo");


you will see the error. BTW, did you use Rik's changeset?

Muhali <muhali>
Fri 28 Mar 2014 09:24:23 AM UTC, comment #2: 

Hi all,

I am insterested in this bug as I have written the two buggy functions. Nevertheless, I haven't been able to reproduce the problem. I did


>> plot([1,2,3]);
>> hgsave("foo");
warning: hgsave: no extension given, using .ofig
warning: called from
    hgsave at line 59 column 5
>> hgload("foo")
warning: hgload: no extension given, trying with .ofig
warning: called from
    hgload at line 35 column 5


and it worked. So I tried


>> A = [1,1,1];
>> save "foo" A
>> hgload("foo")
warning: hgload: no extension given, trying with .ofig
warning: called from
    hgload at line 35 column 5


and it worked. Then I removed the file foo.ofig and I got


>> hgload("foo")
warning: hgload: no extension given, trying with .ofig
warning: called from
    hgload at line 35 column 5
error: hgload: no such file
error: called from:
error:   /home/max/src/octave/build/../scripts/plot/util/hgload.m at line 42, column 5


that is what I would have expected. So, I put a file foo.m in the current directory, getting again


>> hgload("foo")
warning: hgload: no extension given, trying with .ofig
warning: called from
    hgload at line 35 column 5
error: hgload: no such file
error: called from:
error:   /home/max/src/octave/build/../scripts/plot/util/hgload.m at line 42, column 5


that seems ok to me. Then I tried to plot, save and load again and it worked as in the previous case. So I haven't tested the right (faulty) case, or the behaviour I expect isn't the right one. Can you please help me understand the problem? Thanks!

Massimiliano Fasi <mfasi>
Fri 28 Mar 2014 12:21:06 AM UTC, comment #1: 

This was partially fixed in changeset

http://hg.savannah.gnu.org/hgweb/octave/rev/70d9db29db6f

But as Muhali noted on the mailing list (and I can confirm), there is still a problem if a file named "foo" exists in the same directory as "foo.ofig".

Based on the description of the function, it should probably add the ".ofig" extension unconditionally if the given string argument has no file extension.

Mike Miller <mtmiller>
Group Member
Thu 27 Mar 2014 02:30:30 PM UTC, original submission:  

If there is a file 'foo.ofig' plus a file 'foo.m' in the current directory (or anywhere in the load path), the command

hgload("foo")

does not work. In this part of the hgload function


  ## Check file existence
  if (! exist (filename))
    [~, ~, ext] = fileparts (filename);
    if (isempty (ext))
      filename = [filename ".ofig"];
    endif
    if (! exist (filename))
      error ("hgload: unable to locate file %s", filename);
    endif
  endif


the check is incomplete, as it finds foo.m.

Muhali <muhali>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #31064:  hgload.patch added by mfasi (1017B - text/x-diff)

 

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 mfasi (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by muhali (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-03-28 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2014-03-28 rik5 StatusConfirmed Ready For Test
    2014-03-28 mfasi Attached File- Added hgload.patch, #31064
    2014-03-28 mtmiller CategoryNone Octave Function
        Item GroupNone Incorrect Result
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code