From c0c082afee9cc49415f6b71527f4d0211d50f811 Mon Sep 17 00:00:00 2001 From: heinezen Date: Wed, 20 Nov 2024 05:41:23 +0100 Subject: [PATCH] util: Allow setting executable flags for temp file. --- libopenage/util/file.cpp | 12 ++++++++++-- libopenage/util/file.h | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libopenage/util/file.cpp b/libopenage/util/file.cpp index 4a010c119a..d035ee34f2 100644 --- a/libopenage/util/file.cpp +++ b/libopenage/util/file.cpp @@ -122,12 +122,20 @@ std::ostream &operator<<(std::ostream &stream, const File &file) { return stream; } -File File::get_temp_file() { +File File::get_temp_file(bool executable) { fslike::Directory temp_dir = fslike::Directory::get_temp_directory(); std::string file_name = std::tmpnam(nullptr); std::ostringstream dir_path; temp_dir.repr(dir_path); - File file_wrapper = File(dir_path.str() + file_name, 0777); + + if (executable) { + // 0755 == rwxr-xr-x + File file_wrapper = File(dir_path.str() + file_name, 0755); + return file_wrapper; + } + + // 0644 == rw-r--r-- + File file_wrapper = File(dir_path.str() + file_name, 0644); return file_wrapper; } diff --git a/libopenage/util/file.h b/libopenage/util/file.h index 44d24b027a..e2c9a8a992 100644 --- a/libopenage/util/file.h +++ b/libopenage/util/file.h @@ -100,7 +100,7 @@ class OAAPI File { std::vector get_lines(); std::shared_ptr get_fileobj() const; - static File get_temp_file(); + static File get_temp_file(bool executable = false); protected: std::shared_ptr filelike;