From b969b0bae1a06029b8613d147aaed8bf9b6dab1c Mon Sep 17 00:00:00 2001 From: Josh Grosse Date: Fri, 27 Dec 2024 19:20:33 -0500 Subject: [PATCH] fix: use process umask for new files. (#7195) --- libtransmission/utils.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libtransmission/utils.cc b/libtransmission/utils.cc index ce709002c..c9e968064 100644 --- a/libtransmission/utils.cc +++ b/libtransmission/utils.cc @@ -32,6 +32,7 @@ #include /* CommandLineToArgv() */ #else #include +#include /* umask() */ #endif #define UTF_CPP_CPLUSPLUS 201703L @@ -193,6 +194,14 @@ bool tr_file_save(std::string_view filename, std::string_view contents, tr_error { return false; } +#ifndef _WIN32 + // set file mode per settings umask() + { + auto const val = ::umask(0); + ::umask(val); + fchmod(fd, 0666 & ~val); + } +#endif // Save the contents. This might take >1 pass. auto ok = true;