From 2670bbdcc870ab228b1d5d8e4c128406c1f956e4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 13 May 2022 13:21:01 +0200 Subject: [PATCH] io/FileOutputStream: simplify OpenTempFile() call --- src/io/FileOutputStream.cxx | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/io/FileOutputStream.cxx b/src/io/FileOutputStream.cxx index 939586ebf..ec573b5f3 100644 --- a/src/io/FileOutputStream.cxx +++ b/src/io/FileOutputStream.cxx @@ -190,28 +190,26 @@ OpenTempFile(FileDescriptor directory_fd, #endif /* HAVE_O_TMPFILE */ inline void -FileOutputStream::OpenCreate(bool visible) +FileOutputStream::OpenCreate([[maybe_unused]] bool visible) { #ifdef HAVE_O_TMPFILE /* try Linux's O_TMPFILE first */ - is_tmpfile = !visible && OpenTempFile(directory_fd, fd, GetPath()); - if (!is_tmpfile) { -#endif - /* fall back to plain POSIX */ - if (!fd.Open( -#ifdef __linux__ - directory_fd, -#endif - GetPath().c_str(), - O_WRONLY|O_CREAT|O_TRUNC, - 0666)) - throw FormatErrno("Failed to create %s", - GetPath().c_str()); -#ifdef HAVE_O_TMPFILE + if (!visible && OpenTempFile(directory_fd, fd, GetPath())) { + is_tmpfile = true; + return; } -#else - (void)visible; #endif + + /* fall back to plain POSIX */ + if (!fd.Open( +#ifdef __linux__ + directory_fd, +#endif + GetPath().c_str(), + O_WRONLY|O_CREAT|O_TRUNC, + 0666)) + throw FormatErrno("Failed to create %s", + GetPath().c_str()); } inline void