Skip to content

Commit

Permalink
Merge pull request #412 from vibe-d/file_hotfix
Browse files Browse the repository at this point in the history
Fix a regression introduced by #411
  • Loading branch information
l-kramer authored Sep 13, 2024
2 parents 4321396 + 88c47b5 commit 48bd2b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 7 additions & 5 deletions source/vibe/core/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion tests/vibe.core.file.d
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 48bd2b0

Please sign in to comment.