You are here

function module_builder_create_directory in Module Builder 6.2

Same name in this branch
  1. 6.2 includes/common_version_7.inc \module_builder_create_directory()
  2. 6.2 includes/common_version.inc \module_builder_create_directory()
Same name and namespace in other branches
  1. 7 includes/common_version_7.inc \module_builder_create_directory()
  2. 7 includes/common_version.inc \module_builder_create_directory()

Run through Drupal's directory creation and checking stuff, adding a version subfolder for common directories.

Parameters

$directory: A directory path. Should be either absolute or relative; the latter will be taken to mean it's inside the Drupal /files directory.

$common: Boolean to indicate whether this directory is common across several Drupal installations. If set, the actual directory used will be a subdirectory with a version number: eg path/to/dir/6

1 call to module_builder_create_directory()
_module_builder_get_hooks_directory in includes/common.inc
Get a directory to save or read hook data files.

File

includes/common_version.inc, line 22
common_version.inc Stuff needed both by module and drush command. Functions that need to differ for versions of Drupal. This file is the default fallback, and covers Drupal 5 and 6.

Code

function module_builder_create_directory(&$directory, $common = FALSE) {
  if (substr($directory, 0, 1) == '/') {

    // absolute path

    //print 'starts with /';
  }
  else {

    // Relative, and so assumed to be in Drupal's files folder.
    // sanity check. need to verify /files exists before we do anything. see http://drupal.org/node/367138
    $files = file_create_path();
    file_check_directory($files, FILE_CREATE_DIRECTORY);
    $directory = file_create_path($directory);
  }

  // Note that recursive stuff won't work here!
  // You really should make sure the dir exists yourself.
  file_check_directory($directory, FILE_CREATE_DIRECTORY);

  // If the directory is common, append the version number subdir.
  if ($common) {

    // $directory has no trailing / at this point: file_check_directory removes it.
    $directory = $directory . '/' . _module_builder_drupal_major_version();
    file_check_directory($directory, FILE_CREATE_DIRECTORY);
  }
}