bugGNU Octave - Bugs: bug #43872, tempname does not provide unique...

 
 

bug #43872: tempname does not provide unique temporary name in Windows.

Submitter:  John Donoghue <lostbard>
Submitted:  Mon 22 Dec 2014 06:19:50 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  lostbard
Originator Name:  JohnD Open/Closed:  * Closed
Release:  * dev Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 02 Jan 2015 05:22:49 PM UTC, comment #12: 

Okay, pushed to the development branch here (http://hg.savannah.gnu.org/hgweb/octave/rev/d8fd3842a507).  Marking bug as fixed and closing report.

Rik <rik5>
Group administrator
Fri 02 Jan 2015 01:41:13 PM UTC, comment #11: 

Looks good to me - you going to push, or should I?

John Donoghue <lostbard>
Group Member
Fri 02 Jan 2015 05:59:51 AM UTC, comment #10: 

I took a look at the patch and cleaned up a few things.  If no prefix is specified the old tempnam would use the prefix "file" so I added that.  I also simplified the loading of tempname.h to just a single extern since we are not LIBC and never will be.  In do_get_temp_directory I segregated the cases in to Windows vs. UNIX so that the UNIX branch never needs to check the TEMP environment variable.  I've uploaded the cset.  It passes all tests for me.

(file #32746)

Rik <rik5>
Group administrator
Thu 01 Jan 2015 04:15:40 PM UTC, comment #9: 

New patch attached using gen_tempname




(file #32743)

John Donoghue <lostbard>
Group Member
Fri 26 Dec 2014 04:21:14 AM UTC, comment #8: 

Linking bug to an earlier report of the same issue with some more discussion about using gnulib.

Rik <rik5>
Group administrator
Thu 25 Dec 2014 04:32:09 PM UTC, comment #7: 

Rather than write our own routines to re-perform the work of tempnam, I think it would be better to use whatever we can from gnulib.

One way would be to check for the appropriate environment variable and the dir arg being set, and in such a case use unsetenv temporarily before calling tempnam.

Another choice would be to use get_tempname from gnulib directly.  See https://github.com/gagern/gnulib/blob/master/lib/tempname.h.
In this case we set up the template string with either P_tmpdir or the dir_arg if it is set and then call get_tempname.

Rik <rik5>
Group administrator
Thu 25 Dec 2014 01:38:00 PM UTC, comment #6: 
John Donoghue <lostbard>
Group Member
Tue 23 Dec 2014 03:33:28 PM UTC, comment #5: 

How about this (attached) which checks the final name if the path was modified and appends to the name if it exists to make it unique.



(file #32704)

John Donoghue <lostbard>
Group Member
Tue 23 Dec 2014 11:43:04 AM UTC, comment #4: 

According to msdn [1]:


The name returned by _tempnam will be a concatenation of prefix and a sequential number, which will combine to create a unique file name for the specified directory. _tempnam generates file names that have no extension.



[1] http://msdn.microsoft.com/en-us/library/hs3e7355.aspx

John Donoghue <lostbard>
Group Member
Tue 23 Dec 2014 11:25:40 AM UTC, comment #3: 

On my win7, 64 bit machine.


>> tempname
ans = C:\Users\JOHN\AppData\Local\Temp\oct-2
>> tempname
ans = C:\Users\JOHN\AppData\Local\Temp\oct-4
>> tempname
ans = C:\Users\JOHN\AppData\Local\Temp\oct-41
>> tempname
ans = C:\Users\JOHN\AppData\Local\Temp\oct-42
>> tempname
ans = C:\Users\JOHN\AppData\Local\Temp\oct-46
>>


It isn't quite just doing an increment each time, but it's close.


John Donoghue <lostbard>
Group Member
Tue 23 Dec 2014 06:13:06 AM UTC, comment #2: 

Well, I think it is wrong, but apparently an incrementing number is all that tempnam under Windows does.


Rik <rik5>
Group administrator
Tue 23 Dec 2014 05:58:19 AM UTC, comment #1: 

There seems to be something wrong with the tempnam function under Windows.  Even without the modifications for bug #43844, the returned value should have 6 characters worth of randomness.

For example, on a Linux machine


tempname ()
ans = /tmp/oct-LCigCo


What do repeated invocations of just tempname produce on Windows?


tempname ()
tempname ()
tempname ()
tempname ()


Is it just a numerically increasing filename?

Rik <rik5>
Group administrator
Mon 22 Dec 2014 06:19:50 PM UTC, original submission:  

Under windows, the temporary file naming is rather deterministic, and each time I run octave, I can see the sequence of file names used.

In part because of that, if specifying your own directory, the temporary name may already exist.

For example, if I have a directory c:\\temp\\oct-2.

On first call of tempname:


>> a = tempname("c:\\temp")
a = c:\temp\oct-2
>>


The fix for Bug 43844 [1]  makes the function no longer check if it is/was a unique temporary name.

The Linux tempnam function provides a more random filename and so is less likely to already exist.


[1] https://savannah.gnu.org/bugs/?43844


John Donoghue <lostbard>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #32746:  tempname.cset added by rik5 (6KiB - application/octet-stream)
file #32743:  bug43872-fix.patch added by lostbard (5KiB - text/x-patch)
file #32704:  bug43872.patch added by lostbard (1KiB - application/octet-stream)

 

Digest:
   bug dependencies.

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by avinoam
  • -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 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-01-02 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2015-01-02 rik5 Attached File- Added tempname.cset, #32746
    2015-01-01 lostbard Attached File- Added bug43872-fix.patch, #32743
    2014-12-26 rik5 Dependencies- Depends on bugs #36688
    2014-12-25 lostbard StatusNeed Info Ready For Test
        Assigned toNone lostbard
    2014-12-23 avinoam Carbon-Copy- Added avinoam
    2014-12-23 lostbard Attached File- Added bug43872.patch, #32704
    2014-12-23 rik5 StatusNone Need Info
    2014-12-22 lostbard Summarytempname doesnt provide unique temporty name in Windows. tempname does not provide unique temporary name in Windows.

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code