From 5bbf07beb8d5887f2f9b313a098ff49d1ce0e487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 6 Oct 2016 22:15:25 +0200 Subject: [PATCH] Fix FileStream.close and let the file test clean up after itself. --- source/vibe/core/file.d | 13 +++++++++++-- tests/vibe.core.file.d | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/source/vibe/core/file.d b/source/vibe/core/file.d index 943cfa2..03d0fdb 100644 --- a/source/vibe/core/file.d +++ b/source/vibe/core/file.d @@ -393,8 +393,17 @@ struct FileStream { m_size = eventDriver.files.getSize(fd); } - this(this) { eventDriver.files.addRef(m_fd); } - ~this() { eventDriver.files.releaseRef(m_fd); } + this(this) + { + if (m_fd != FileFD.init) + eventDriver.files.addRef(m_fd); + } + + ~this() + { + if (m_fd != FileFD.init) + eventDriver.files.releaseRef(m_fd); + } @property int fd() { return m_fd; } diff --git a/tests/vibe.core.file.d b/tests/vibe.core.file.d index 5d06173..db48d09 100644 --- a/tests/vibe.core.file.d +++ b/tests/vibe.core.file.d @@ -21,4 +21,7 @@ void main() f.seek(2); f.read(dst); assert(dst[] == [3, 4, 5, 6, 7]); + f.close(); + + removeFile("test.dat"); }