On 20/02/09 18:01, Matt Wozniski wrote:
> On Fri, Feb 20, 2009 at 4:16 AM, Tony Mechelynck wrote:
>> On 20/02/09 05:45, Bram Moolenaar wrote:
>>> Matt Wozniski wrote:
>>>
>>>> I ask because this seems to be causing a race condition:
>>>> GetTempFileName() checks if a file exists, finds a name that doesn't
>>>> exist, creates it, and returns the name back to the caller.  It
>>>> creates it so that future calls to GetTempFileName() won't choose the
>>>> same file, since it now exists.  But, deleting it before being done
>>>> with it introduces a race condition: vim calls GetTempFileName(), then
>>>> DeleteFile(), then another process calls GetTempFileName(), and now
>>>> vim has the path to a file that didn't exist when it asked for a
>>>> unique, non-existant file, but exists now, and is no longer safe for
>>>> vim to use.
>> Also, what about the case when a script might use tempname() in order to get
>> a unique name for a directory? If you (Matt) leave the file lying around,
>> directory creation will IIUC be impossible, which breaks compatibility with
>> existing behaviour.
>
> That's already requires workarounds, though - if a script uses
> mkdir(tempname()), vim won't remove the temporary directory, and the
> script author needs to have his own VimLeave autocmd for cleaning it
> up.  Breaking backwards compatibility when the old behavior is wrong
> is a good thing.
>
> ~Matt
>

I'm assuming that any existing script doing this kind of stuff will 
either remove the directory at the VimLeave event, or rename it at some 
point between creating it and exiting (possibly depending on how the 
user interacts with the script before exiting Vim). IOW the old 
behaviour (creating a directory with a pseudorandom name) is not 
necessarily and unredeemably evil -- it could be part of a perfectably 
acceptable, even laudable, whole which, in most of its possible details, 
falls outside the scope of the present discussion.

Best regards,
Tony.
-- 
Why does man kill?  He kills for food.  And not only food: frequently
there must be a beverage.
                -- Woody Allen, "Without Feathers"

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui