Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix definition of static functions for creating temp files/dirs #1709

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading