From ce9faec1c1e13a5afa87b705a113be68d445a36b Mon Sep 17 00:00:00 2001 From: v1ne Date: Fri, 26 Jul 2019 00:27:50 +0200 Subject: [PATCH] FileStream: Forbid seek(.) or truncate(.) when appending to a file Those functions do not work for files opened for appending. Make this clear. --- source/vibe/core/file.d | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/vibe/core/file.d b/source/vibe/core/file.d index 4bd1cda..fcec414 100644 --- a/source/vibe/core/file.d +++ b/source/vibe/core/file.d @@ -472,6 +472,7 @@ struct FileStream { void seek(ulong offset) { + enforce(ctx.mode != FileMode.append, "File opened for appending, not random access. Cannot seek."); ctx.ptr = offset; } @@ -479,6 +480,8 @@ struct FileStream { void truncate(ulong size) { + enforce(ctx.mode != FileMode.append, "File opened for appending, not random access. Cannot truncate."); + auto res = asyncAwaitUninterruptible!(FileIOCallback, cb => eventDriver.files.truncate(m_fd, size, cb) );