| 278 | |
| 279 | |
| 280 | Try<Path> getTemporaryDirectoryPath() { |
| 281 | if (temporaryDirectory.isSome()) { |
| 282 | return temporaryDirectory.get(); |
| 283 | } |
| 284 | |
| 285 | // TODO(bevers): Add a libprocess-specific override for the system-wide |
| 286 | // `TMPDIR`, for example `LIBPROCESS_TMPDIR`. |
| 287 | const string tmpdir = |
| 288 | os::getenv("TMPDIR").getOrElse(LIBPROCESS_DEFAULT_TMPDIR); |
| 289 | |
| 290 | const string pathTemplate = path::join(tmpdir, "libprocess.XXXXXX"); |
| 291 | |
| 292 | // TODO(bevers): Add an atexit-handler that cleans up the directory. |
| 293 | Try<string> dir = os::mkdtemp(pathTemplate); |
| 294 | if (dir.isError()) { |
| 295 | return Error(dir.error()); |
| 296 | } |
| 297 | |
| 298 | temporaryDirectory = dir.get(); |
| 299 | |
| 300 | VLOG(1) << "Using path " << dir.get() << " to store temporary files"; |
| 301 | |
| 302 | return temporaryDirectory.get(); |
| 303 | } |
| 304 | |
| 305 | |
| 306 | // TODO(alexr): Consider making this asynchronous. |