Skip to content

Commit

Permalink
Merge branch 'master' into clang-tidy-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
haytham918 authored Nov 21, 2024
2 parents 2447d6e + 4f0de63 commit 60f2538
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
15 changes: 11 additions & 4 deletions libopenage/util/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

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
4 changes: 2 additions & 2 deletions libopenage/util/fslike/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <cstdio>
#include <dirent.h>
#include <fcntl.h>
#include <iostream>
#include <filesystem>
#include <iostream>
#include <sys/stat.h>
#include <sys/types.h>
#include <utility>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 60f2538

Please sign in to comment.