Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Add options for finding temp directory
Browse files Browse the repository at this point in the history
On Ubuntu, $TMPDIR is not set. So, add an option to try
/var/tmp or /tmp directories.
  • Loading branch information
swaroop-sridhar committed Apr 13, 2019
1 parent 3222c89 commit 3de5b31
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/corehost/common/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ namespace pal
inline bool pal_clrstring(const pal::string_t& str, std::vector<char>* out) { return pal_utf8string(str, out); }
inline bool clr_palstring(const char* cstr, pal::string_t* out) { out->assign(cstr); return true; }

inline bool mkdir(const pal::char_t* dir, int mode) { return mkdir(dir, mode) == 0; }
inline bool rmdir(const pal::char_t* path) { return rmdir(path) == 0; }
inline bool mkdir(const pal::char_t* dir, int mode) { return ::mkdir(dir, mode) == 0; }
inline bool rmdir(const pal::char_t* path) { return ::rmdir(path) == 0; }
inline int rename(const pal::char_t* old_name, const pal::char_t* new_name) { return ::rename(old_name, new_name); }
inline int remove(const pal::char_t* path) { return ::remove(path); }
inline int get_pid() { return getpid(); }
Expand Down
26 changes: 24 additions & 2 deletions src/corehost/common/pal.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,30 @@ bool pal::get_default_servicing_directory(string_t* recv)

bool pal::get_temp_directory(pal::string_t& tmp_dir)
{
pal::getenv(_X("TMPDIR"), &tmp_dir);
return pal::realpath(&tmp_dir);
// First, check for the POSIX standard environment variable
if (pal::getenv(_X("TMPDIR"), &tmp_dir))
{
return pal::realpath(&tmp_dir);
}

// On non-compliant systems (ex: Ubuntu) try /var/tmp or /tmp directories.
// /var/tmp is prefered since its contents are expected to survive across
// machine reboot.
pal::string_t _var_tmp = _X("/var/tmp/");
if (pal::realpath(&_var_tmp))
{
tmp_dir.assign(_var_tmp);
return true;
}

pal::string_t _tmp = _X("/tmp/");
if (pal::realpath(&_tmp))
{
tmp_dir.assign(_tmp);
return true;
}

return false;
}

bool pal::get_global_dotnet_dirs(std::vector<pal::string_t>* recv)
Expand Down
4 changes: 2 additions & 2 deletions src/corehost/corehost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ int exe_start(const int argc, const pal::char_t* argv[])
return StatusCode::AppHostExeNotBoundFailure;
}

app_root.assign(app_path);

append_path(&app_path, embedded_app_name.c_str());
if (!pal::realpath(&app_path))
{
trace::error(_X("The application to execute does not exist: '%s'."), app_path.c_str());
return StatusCode::LibHostAppRootFindFailure;
}

app_root.assign(get_directory(app_path));

#else
pal::string_t own_name = strip_executable_ext(get_filename(host_path));

Expand Down

0 comments on commit 3de5b31

Please sign in to comment.