bugGNU Octave - Bugs: bug #48080, file_in_loadpath fails after saving

 
 

bug #48080: file_in_loadpath fails after saving

Submitter:  Rik <rik5>
Submitted:  Wed 01 Jun 2016 04:24:10 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 21 Jun 2016 02:57:06 PM UTC, comment #4: 

It does seem like it would be a good idea.  How major a change is this likely to be?

In load-path.cc for the update function called by rehash I see


void
load_path::do_update (void) const
{
  // I don't see a better way to do this because we need to
  // preserve the correct directory ordering for new files that
  // have appeared.

  default_loader.clear ();

  loader_map.clear ();

  for (dir_info_list_iterator p = dir_info_list.begin ();
       p != dir_info_list.end ();
       p++)
    {
      dir_info& di = *p;

      di.update ();

      add (di, true, "", true);
    }
}


I don't like the look of the comment.  But it does appear that loader_map is a std::map which means it should be easy to add a new key/val pair.  I think load-path.h needs to expose a new form of add() which takes a filename, rather than a directory as is done currently.


Rik <rik5>
Group administrator
Tue 21 Jun 2016 09:04:05 AM UTC, comment #3: 

Note that explicitly updating the hash table after all file-creation events would also solve bug #31080.

Lachlan Andrew <lachlan>
Thu 02 Jun 2016 12:51:06 AM UTC, comment #2: 

Pantxo, Rik said that "pause" does not fix the issue.

I think that is because the ageing of files (and seemingly also directories) only checks for existence if the file has not been accessed since the last command line was processed.  Rehash bypasses that ageing process, but pause doesn't alter the timestamp of the last command line.

Rik's problem could be fixed if save/fopen/hgsave/imwrite etc add the file to the hash table explicitly.  That would be faster than a complete rehash of the whole load path.

Lachlan Andrew <lachlan>
Wed 01 Jun 2016 09:48:47 PM UTC, comment #1: 

Hi,

hgsave is not needed, saving data files or creating a file in a script/function is enough to trigger the bug, e.g:


a = 1;
save foo.var a
## "rehash" here is a workaround
filp = file_in_loadpath ("foo.var");
if (isempty (filp))
  error ("File foo.var not found");
endif


It is not a duplicate but resembles bug #40319. Besides "pause", "rehash" also fixes the issue.

Pantxo Diribarne <pantxo>
Group Member
Wed 01 Jun 2016 04:24:10 PM UTC, original submission:  

Run the attached script tst_hgsave.m under Octave.

The script is


graphics_toolkit qt
unlink ("foo.var");
clear

sombrero ();
hgsave (gcf, "foo.var");

filp = file_in_loadpath ("foo.var");
if (isempty (filp))
  error ("File foo.var not found");
endif


The file foo.var is created by hgsave, but file_in_loadpath fails to detect it.  However, once Octave has returned to a command prompt, file_in_loadpath is accurate.

Putting in a pause(1) statement after the hgsave and before the call to file_in_loadpath does not make this work.  However, putting in a keyboard statement which forces a return to a debug prompt does make it work.


Rik <rik5>
Group administrator

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #37336:  tst_hgsave.m added by rik5 (185B - d2l/unknowntype)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by lachlan (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by rik5 (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-06-21 rik5 StatusNone Confirmed
    2016-06-01 pantxo Summaryfile_in_loadpath fails after hgsave file_in_loadpath fails after saving
    2016-06-01 rik5 Attached File- Added tst_hgsave.m, #37336

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code