Skip to content

Commit

Permalink
util: Allow setting executable flags for temp file.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Nov 20, 2024
1 parent 3d6a3ac commit c0c082a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions libopenage/util/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion libopenage/util/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class OAAPI File {
std::vector<std::string> get_lines();
std::shared_ptr<filelike::FileLike> get_fileobj() const;

static File get_temp_file();
static File get_temp_file(bool executable = false);

protected:
std::shared_ptr<filelike::FileLike> filelike;
Expand Down

0 comments on commit c0c082a

Please sign in to comment.