From 8e463e63ea2e837a442c55580b1bb0d72ec5b25f Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 11 Mar 2021 20:48:44 +1100 Subject: [PATCH] Do not use replace write method when writing to a non-regular file Fixes #4098 --- src/file.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/file.cc b/src/file.cc index 3424afef..8c9705b5 100644 --- a/src/file.cc +++ b/src/file.cc @@ -361,7 +361,8 @@ void write_buffer_to_file(Buffer& buffer, StringView filename, bool replace = method == WriteMethod::Replace; bool force = flags & WriteFlags::Force; - if ((replace or force) and ::stat(zfilename, &st) != 0) + if ((replace or force) and (::stat(zfilename, &st) != 0 or + (sb.st_mode & S_IFMT) != S_IFREG)) { force = false; replace = false;