Skip to content

Commit

Permalink
modified file.cpp to utilize get_temp_dir from directory.cpp and then…
Browse files Browse the repository at this point in the history
… place a file into it
  • Loading branch information
alamt22 authored and heinezen committed Nov 18, 2024
1 parent 1195687 commit 8c525dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions libopenage/util/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "util/filelike/python.h"
#include "util/path.h"
#include "util/strings.h"
#include "util/fslike/directory.h"


namespace openage::util {
Expand Down Expand Up @@ -122,11 +123,12 @@ std::ostream &operator<<(std::ostream &stream, const File &file) {
}

static File get_temp_file() {
std::FILE* tmp_file = std::tmpfile();
int temp_fd = fileno(tmp_file);
std::string tf_path = "/proc/self/fd/" + std::to_string(temp_fd);
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(tf_path, mode);
File file_wrapper = File(dir_path.str() + file_name, mode);
return file_wrapper;
}

Expand Down
3 changes: 2 additions & 1 deletion libopenage/util/fslike/directory.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ class Directory : public FSLike {
* basically basepath + "/".join(parts)
*/
std::string resolve(const Path::parts_t &parts) const;

std::tuple<struct stat, int> do_stat(const Path::parts_t &parts) const;

std::string basepath;
};
} // namespace fslike
Expand Down

0 comments on commit 8c525dd

Please sign in to comment.