function _less_ensure_directory in Less CSS Preprocessor 7.4
Same name and namespace in other branches
- 8 less.module \_less_ensure_directory()
- 7.3 less.module \_less_ensure_directory()
Helper function that attempts to create a folder if it doesn't exist.
Locks are used to help avoid concurrency collisions.
Parameters
string $directory_path: Directory of which to create/confirm existence.
Return value
bool Value indicating existence of directory.
1 call to _less_ensure_directory()
- _less_process_file in includes/
less.process.inc - Process a .less file and save the compiled styles.
File
- ./
less.module, line 546 - Handles compiling of .less files.
Code
function _less_ensure_directory($directory_path) {
$is_dir = is_dir($directory_path);
if (!$is_dir) {
$lock_id = 'less_directory_' . md5($directory_path);
// Attempt to create directory only 3 times, else delay is too long.
for ($i = 0; $i < 3; $i++) {
if (lock_acquire($lock_id) && ($is_dir = file_prepare_directory($directory_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS))) {
// Creation was successful, cancel the 'for' loop;
break;
}
lock_wait($lock_id, 1);
}
lock_release($lock_id);
if (!$is_dir) {
// There is a problem with the directory.
$message_vars = array(
'%dir' => $directory_path,
);
watchdog('LESS', 'LESS could not create a directory in %dir', $message_vars, WATCHDOG_ERROR);
if (user_access(LESS_PERMISSION)) {
drupal_set_message(t('LESS could not create a directory in %dir', $message_vars), 'error', FALSE);
}
}
}
return $is_dir;
}