bugGNU Octave - Bugs: bug #41330, fopen (<fname>,...

 
 

bug #41330: fopen (<fname>, "w") creates temp file with different file name

Submitter:  Philip Nienhuis <philipnienhuis>
Submitted:  Fri 24 Jan 2014 09:26:24 AM UTC
   
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Philip Nienhuis Open/Closed:  * Closed
Release:  * dev Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 24 Jan 2014 10:09:15 PM UTC, comment #4: 

Thanks, that trick will help simplifying the code (no more need to track temp file names)

Philip Nienhuis <philipnienhuis>
Group Member
Fri 24 Jan 2014 10:13:36 AM UTC, comment #3: 

Try


fid = fopen (file, flags);
fopen (fid)


John W. Eaton <jwe>
Group administrator
Fri 24 Jan 2014 10:06:54 AM UTC, comment #2: 

Turns out the whole bug is invalid, sorry.
(Maybe I shouldn't work too long evenings on Octave).

The question below still stands - how to get the file name associated with a file handle)

Philip Nienhuis <philipnienhuis>
Group Member
Fri 24 Jan 2014 09:31:55 AM UTC, comment #1: 

Oops - the second example obviously works correct as fopen should have been called with tmpfil

Philip Nienhuis <philipnienhuis>
Group Member
Fri 24 Jan 2014 09:26:24 AM UTC, original submission:  

(Also present in 3.8.0 mingw mxe-cross-built)

Steps to reproduce:

- Put attached script tmpf.m & file template.ods into same subdir.
(tmpf.m reproduced below for clarity:

tmpdir = tmpnam
unpack ("template.ods", tmpdir, "unzip");
tmpfil = tmpnam
fid = fopen (tmpnam, "w+");
fclose (fid);
confirm_recursive_rmdir ("yes");
rmdir (tmpdir, "s")


- Run tmpf.m, note name of temp file <tmpfil> (e.g., /path/to/temp/dir/oct-3)

- Watch contents of temp directory: I get a file called oct-4 instead of oct-3.

It turns out I can very reliably reproduce this on my XP and Win 7 boxes at home.

Furthermore,

>> tmpfil = tmpnam
tmpfil = C:\Home\Philip\LOCALS~1\Temp\oct-21
>> fid = fopen (tmpnam)
fid = -1
>> fid = fopen (tmpnam, 'r')
fid = -1
>> fid = fopen (tmpnam, 'w')
fid =  3
>>


...gets me a temp file called 'oct-24" rather than "oct-21".

The effect is that unlinking temp files gets a bit hard, so over time the temp dir gets cluttered with tens or hundreds of temp files.

As to reproducability:
Sometimes this works OK. But once some unknown condition ("nasal demon"? thanks Jordi for that term!) has been triggered, the above behavior is consistent, also over restarts of Octave.
(Sorry for guessing) I can't put a finger on it, but maybe it is due to the unpack statement of the .ods file (effectively a plain .zip file with .ods suffix). Or maybe it is related to a timing issue in the OS.

Is there a way to find out the file name associated with a particular file handle, or to delete a file by its file handle? That would make it easier to delete temp files and could be a good workaround for this bug.

Philip Nienhuis <philipnienhuis>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #30360:  tmpf.m added by philipnienhuis (194B - text/x-matlab)
file #30361:  template.ods added by philipnienhuis (7KiB - application/vnd.oasis.opendocument.spreadsheet)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by philipnienhuis (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-01-24 philipnienhuis StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
    2014-01-24 philipnienhuis Attached File- Added tmpf.m, #30360
        Attached File- Added template.ods, #30361

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code