July 07, 2014
On Monday, 7 July 2014 at 14:25:54 UTC, Regan Heath wrote:
> If I had to guess, I would say it would still be possible to access the file.

It's documented so. I guess, linux implements file deletion with delete-on-close feature too, if it exists, a separate deletion operation is not needed.
July 07, 2014
On Monday, 7 July 2014 at 12:00:48 UTC, Regan Heath wrote:
> On Mon, 07 Jul 2014 12:17:34 +0100, Joakim <dlang@joakim.airpost.net> wrote:
>
>> On Monday, 7 July 2014 at 10:19:01 UTC, Kagamin wrote:
>>> See if stdio allows you to specify delete sharing when opening the file.
>>
>> I don't know what delete sharing is exactly, but the File constructor simply calls fopen and I don't see any option for the Windows fopen that seems to do it:
>>
>> http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx
>
> The fopen variant that allows you to specify sharing is:
> http://msdn.microsoft.com/en-us/library/8f30b0db.aspx
>
> But it does not mention delete sharing there.
>
> CreateFile allows sharing to be specified for delete however:
> http://msdn.microsoft.com/en-gb/library/windows/desktop/aa363858(v=vs.85).aspx
>
> So... you could:
>  - Call CreateFile giving you a "handle"
>  - Call _open_osfhandle to get a "file descriptor"
>  - Call _fdopen on the file descriptor to get a FILE* for it
>
> But!  I agree with Adam, leave it as a thin wrapper.  Being a windows programmer by trade I would expect the remove to fail, I would not expect all my files to be opened with delete sharing enabled by default.

Thanks for all the info.  I'm looking at it from the point of view of a beginner or someone who just writes a quick D script that does something like this.  They may find it confusing that it works on linux but doesn't work on Windows, especially given the confusing error message.

But it is good practice to close a file before deleting and if D prefers to have thin wrappers around OS APIs, that implies less hand-holding like this, so maybe we just tell such people to close the file first.
July 09, 2014
On Monday, 7 July 2014 at 16:02:33 UTC, Kagamin wrote:
> On Monday, 7 July 2014 at 14:25:54 UTC, Regan Heath wrote:
>> If I had to guess, I would say it would still be possible to access the file.
>
> It's documented so. I guess, linux implements file deletion with delete-on-close feature too, if it exists, a separate deletion operation is not needed.

It's not really a delete on close. The file system link is removed, but there is still a handle open to the location. This ends up working more like a GC, file is not returned for reuse until there are no more references to it.
1 2
Next ›   Last »