Do not use replace write method when writing to a non-regular file

Fixes #4098
This commit is contained in:
Maxime Coste 2021-03-11 20:48:44 +11:00
parent 7f8f748d06
commit 8e463e63ea

View File

@ -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;