function drush_find_tmp

8.0.x filesystem.inc drush_find_tmp()
6.x filesystem.inc drush_find_tmp()
7.x filesystem.inc drush_find_tmp()
4.x drush.inc drush_find_tmp()
5.x filesystem.inc drush_find_tmp()
master filesystem.inc drush_find_tmp()

Returns the path to a temporary directory.

This is a custom version of Drupal's file_directory_path(). We can't directly rely on sys_get_temp_dir() as this path is not valid in some setups for Mac, and we want to honor an environment variable (used by tests).

Related topics

6 calls to drush_find_tmp()
drush_directory_cache in includes/environment.inc
The path to the global cache directory.
drush_tempdir in includes/filesystem.inc
Creates a temporary directory and return its path.
drush_tempnam in includes/filesystem.inc
Creates a temporary file, and registers it so that it will be deleted when drush exits. Whenever possible, drush_save_data_to_temp_file() should be used instead of this function.
make_tmp in commands/make/make.utilities.inc
Find, and possibly create, a temporary directory.
SqlBase::dumpFile in lib/Drush/Sql/SqlBase.php

... See full list

File

includes/filesystem.inc, line 436
Filesystem utilities.

Code

function drush_find_tmp() {
  static $temporary_directory;

  if (!isset($temporary_directory)) {
    $directories = array();

    // Get user specific and operating system temp folders from system environment variables.
    // See http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true
    $tempdir = getenv('TEMP');
    if (!empty($tempdir)) {
      $directories[] = $tempdir;
    }
    $tmpdir = getenv('TMP');
    if (!empty($tmpdir)) {
      $directories[] = $tmpdir;
    }
    // Operating system specific dirs.
    if (drush_is_windows()) {
      $windir = getenv('WINDIR');
      if (isset($windir)) {
        // WINDIR itself is not writable, but it always contains a /Temp dir,
        // which is the system-wide temporary directory on older versions. Newer
        // versions only allow system processes to use it.
        $directories[] = $windir . '/Temp';
      }
    }
    else {
      $directories[] = '/tmp';
    }
    $directories[] = sys_get_temp_dir();

    foreach ($directories as $directory) {
      if (is_dir($directory) && is_writable($directory)) {
        $temporary_directory = $directory;
        break;
      }
    }

    if (empty($temporary_directory)) {
      // If no directory has been found, create one in cwd.
      $temporary_directory = drush_cwd() . '/tmp';
      drush_mkdir($temporary_directory, TRUE);
      if (!is_dir($temporary_directory)) {
        return drush_set_error('DRUSH_UNABLE_TO_CREATE_TMP_DIR', dt("Unable to create a temporary directory."));
      }
      drush_register_file_for_deletion($temporary_directory);
    }
  }

  return $temporary_directory;
}