File needs to be closed on Windows but not on Posix, bug?

Joakim via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 5 13:23:02 PDT 2014


I ran into this when trying to fix the Phobos unit tests and have 
reduced it down to this test file:

import std.stdio, std.file;

void main() {
     auto f = File("test.txt", "w");
     //f.close();
     std.file.remove("test.txt");
}

This compiles and runs fine on linux and the autotester shows 
that it works on all the tested Posix platforms, but it fails on 
Windows with

std.file.FileException at std\file.d(433): test.txt: The process 
cannot access the file because it is being used by another 
process.

Uncommenting the f.close() gets it to work fine on all supported 
platforms, no doubt it has to do with the different OS APIs that 
are being called.

This seems like inconsistent behavior: should I file a bug?


More information about the Digitalmars-d-learn mailing list