Its behaviour is inconsistent with byLine() and byChunk() - which keep File struct internally instead of FILE* pointer. Compare: auto lines = File("/tmp/file.txt").byLine(); writeln(lines); // works auto writer = File("/tmp/file.txt", "w+").lockingTextWriter; writer.put("123"); // fails - the file is already closed!
+1 I spent an hour in frustration because of a line like this: auto buf = File("somefile", "w").lockingTextWriter(); Because the File is temporary, it immediately closes and leaves you with a LockingTextWriter with a bad handle. Since the whole point of wrapping FILE* with File is to manage its lifetime, lockingTextWriter really needs to increment and decrement the ref count.
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/cb67c5d50f3898300e2b314f9f8695ba0fe6b850 Fix Issue 9661 - LockingTextWriter should increment file handle reference count test for locking binary writer https://github.com/dlang/phobos/commit/99002c366bfd57104e943b74cf28adea0721612d Merge pull request #5792 from jercaianu/lockingtextwriter Fix Issue 9661 - LockingTextWriter should increment file handle reference count merged-on-behalf-of: Andrei Alexandrescu <andralex@users.noreply.github.com>
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/cb67c5d50f3898300e2b314f9f8695ba0fe6b850 Fix Issue 9661 - LockingTextWriter should increment file handle reference count https://github.com/dlang/phobos/commit/99002c366bfd57104e943b74cf28adea0721612d Merge pull request #5792 from jercaianu/lockingtextwriter