diff --git a/libopenage/util/file.cpp b/libopenage/util/file.cpp index 3d0d4032ac..d035ee34f2 100644 --- a/libopenage/util/file.cpp +++ b/libopenage/util/file.cpp @@ -14,9 +14,9 @@ #include "util/filelike/native.h" #include "util/filelike/python.h" +#include "util/fslike/directory.h" #include "util/path.h" #include "util/strings.h" -#include "util/fslike/directory.h" namespace openage::util { @@ -122,13 +122,20 @@ std::ostream &operator<<(std::ostream &stream, const File &file) { return stream; } -static 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); - mode_t mode = 0777; - File file_wrapper = File(dir_path.str() + file_name, mode); + + 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; diff --git a/libopenage/util/fslike/directory.cpp b/libopenage/util/fslike/directory.cpp index 5695b3fc13..4143e376e3 100644 --- a/libopenage/util/fslike/directory.cpp +++ b/libopenage/util/fslike/directory.cpp @@ -11,8 +11,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -293,7 +293,7 @@ std::ostream &Directory::repr(std::ostream &stream) { return stream; } -static Directory get_temp_directory() { +Directory Directory::get_temp_directory() { std::string temp_dir_path = std::filesystem::temp_directory_path() / std::tmpnam(nullptr); bool create = true; Directory directory = Directory(temp_dir_path, create);