diff --git a/source/vibe/core/file.d b/source/vibe/core/file.d index 4680b7d0..f3c64fa3 100644 --- a/source/vibe/core/file.d +++ b/source/vibe/core/file.d @@ -699,11 +699,13 @@ scope: ~this() nothrow { - if (this.isOpen) { - if (m_ctx.driver is (() @trusted => cast(shared)eventDriver)()) { - try close(); - catch (Exception e) logException(e, "Closing unclosed FileStream during destruction failed"); - } else logWarn("Destroying FileStream that is still open in a foreign thread (leaked to GC?). This may lead to crashes."); + static if (is(typeof(&eventDriver.files.isUnique))) { + if (this.isOpen) { + if (m_ctx.driver is (() @trusted => cast(shared)eventDriver)() && eventDriver.files.isUnique(m_fd)) { + try close(); + catch (Exception e) logException(e, "Closing unclosed FileStream during destruction failed"); + } else logWarn("Destroying FileStream that is still open in a foreign thread (leaked to GC?). This may lead to crashes."); + } } if (m_fd != FileFD.invalid) diff --git a/tests/vibe.core.file.d b/tests/vibe.core.file.d index d23a9406..f9d52032 100644 --- a/tests/vibe.core.file.d +++ b/tests/vibe.core.file.d @@ -27,9 +27,13 @@ void main() f.write(bytes!(6, 7, 8, 9, 10)); assert(f.size == 10); assert(f.tell == 10); + + auto fcopy = f; ubyte[5] dst; - f.seek(2); + fcopy.seek(2); assert(f.tell == 2); + fcopy = FileStream.init; + f.read(dst); assert(f.tell == 7); assert(dst[] == bytes!(3, 4, 5, 6, 7));