function drush_mkdir

8.0.x filesystem.inc drush_mkdir($path, $required = TRUE)
6.x filesystem.inc drush_mkdir($path, $required = TRUE)
7.x filesystem.inc drush_mkdir($path, $required = TRUE)
4.x drush.inc drush_mkdir($path)
5.x filesystem.inc drush_mkdir($path, $required = TRUE)
master filesystem.inc drush_mkdir($path, $required = TRUE)

Cross-platform compatible helper function to recursively create a directory tree.

If $required is TRUE, then the execution of the current command should be halted if the required directory cannot be created.

Parameters

path: Path to directory to create.

required: If TRUE, then drush_mkdir will call drush_set_error on failure.

Callers should *always* do their own error handling after calling drush_mkdir. If $required is FALSE, then a different location should be selected, and a final error message should be displayed if no usable locations can be found.

See also

drush_directory_cache().

Related topics

27 calls to drush_mkdir()
DrushFileCache::set in includes/cache.inc
Store data in the persistent cache.
DrushMakeProject::findDownloadLocation in commands/make/make.project.inc
Determine the location to download project to.
DrushMakeProject::getTranslations in commands/make/make.project.inc
Retrieve translations for this project.
DrushMakeProject_Core::findDownloadLocation in commands/make/make.project.inc
Determine the location to download project to.
drush_archive_dump in commands/core/archive.drush.inc
Command callback. Generate site archive file.

... See full list

File

includes/filesystem.inc, line 355
Filesystem utilities.

Code

function drush_mkdir($path, $required = TRUE) {
  if (!is_dir($path)) {
    if (drush_mkdir(dirname($path))) {
      if (@mkdir($path)) {
        return TRUE;
      }
      elseif (is_dir($path) && is_writable($path)) {
        // The directory was created by a concurrent process.
        return TRUE;
      }
      else {
        if (!$required) {
          return FALSE;
        }
        if (is_writable(dirname($path))) {
          return drush_set_error('DRUSH_CREATE_DIR_FAILURE', dt('Unable to create !dir.', array('!dir' => preg_replace('/\w+\/\.\.\//', '', $path))));
        }
        else {
          return drush_set_error('DRUSH_PARENT_NOT_WRITABLE', dt('Unable to create !newdir in !dir. Please check directory permissions.', array('!newdir' => basename($path), '!dir' => realpath(dirname($path)))));
        }
      }
    }
    return FALSE;
  }
  else {
    if (!is_writable($path)) {
      if (!$required) {
        return FALSE;
      }
      return drush_set_error('DRUSH_DESTINATION_NOT_WRITABLE', dt('Directory !dir exists, but is not writable. Please check directory permissions.', array('!dir' => realpath($path))));
    }
    return TRUE;
  }
}