You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/12/10 02:02:10 UTC

[03/12] mesos git commit: Stout: Added logic for TMPDIR environment variable in `os::temp`.

Stout: Added logic for TMPDIR environment variable in `os::temp`.

`TMPDIR` is a POSIX-standard environment variable which can be used
to specify a temporary directory.  This variable is currently read
in the agent tests, but ignored in other parts of the codebase.
(`os::temp` is commonly used by `os::mkdtemp`.)

This commit is one of two commits that will normalize the location
of the temporary directory.

Review: https://reviews.apache.org/r/54489/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ca0a8d55
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ca0a8d55
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ca0a8d55

Branch: refs/heads/master
Commit: ca0a8d552cd098593c3c3b0f76d5215846de7120
Parents: b9ef614
Author: Alex Clemmer <cl...@gmail.com>
Authored: Thu Dec 8 17:25:06 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Fri Dec 9 18:01:31 2016 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/posix/temp.hpp   | 10 +++++++++-
 3rdparty/stout/include/stout/os/windows/temp.hpp |  7 +++++--
 2 files changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ca0a8d55/3rdparty/stout/include/stout/os/posix/temp.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/temp.hpp b/3rdparty/stout/include/stout/os/posix/temp.hpp
index 823c97b..cdc4386 100644
--- a/3rdparty/stout/include/stout/os/posix/temp.hpp
+++ b/3rdparty/stout/include/stout/os/posix/temp.hpp
@@ -15,12 +15,20 @@
 
 #include <string>
 
+#include <stout/os/getenv.hpp>
+
 
 namespace os {
 
+// Attempts to resolve the system-designated temporary directory before
+// back on a sensible default. On POSIX platforms, this involves checking
+// the POSIX-standard `TMPDIR` environment variable before falling
+// back to `/tmp`.
 inline std::string temp()
 {
-  return "/tmp";
+  Option<std::string> tmpdir = os::getenv("TMPDIR");
+
+  return tmpdir.getOrElse("/tmp");
 }
 
 } // namespace os {

http://git-wip-us.apache.org/repos/asf/mesos/blob/ca0a8d55/3rdparty/stout/include/stout/os/windows/temp.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/temp.hpp b/3rdparty/stout/include/stout/os/windows/temp.hpp
index d1169df..639f1aa 100644
--- a/3rdparty/stout/include/stout/os/windows/temp.hpp
+++ b/3rdparty/stout/include/stout/os/windows/temp.hpp
@@ -20,12 +20,15 @@
 
 namespace os {
 
+// Attempts to resolve the system-designated temporary directory before
+// falling back to a sensible default. On Windows, this involves checking
+// (in this order) environment variables for `TMP`, `TEMP`, and `USERPROFILE`
+// followed by the Windows directory (`::GetTimePath`).  In the unlikely event
+// where none of these are found, this function returns the current directory.
 inline std::string temp()
 {
-  // Get temp folder for current user.
   char temp_folder[MAX_PATH + 2];
   if (::GetTempPath(MAX_PATH + 2, temp_folder) == 0) {
-    // Failed, try current folder.
     if (::GetCurrentDirectory(MAX_PATH + 2, temp_folder) == 0) {
       // Failed, use relative path.
       return ".";