You are here

private function DrupalFileCache::check_filecache_directory in File Cache 7

1 call to DrupalFileCache::check_filecache_directory()
DrupalFileCache::__construct in ./filecache.inc
Construct DrupalFileCache for specified cache bin.

File

./filecache.inc, line 117
DrupalFileCache class that implements DrupalCacheInterface.

Class

DrupalFileCache

Code

private function check_filecache_directory() {
  $t = get_t();
  $critical_message = FALSE;
  if (!is_dir($this->directory)) {
    if (!file_exists($this->directory)) {
      if (filecache_is_readdeleteonly()) {
        watchdog('filecache', 'Need to create directory %dir but not running in webserver and permissions of created directory would become wrong', array(
          '%dir' => $this->directory,
        ), WATCHDOG_NOTICE);
        return FALSE;
      }

      // Directory does not exist. Try to create it.
      if (!mkdir($this->directory, FILECACHE_DIRECTORY_MODE, TRUE)) {
        $critical_message = $t('%dir does not exist and cannot be created. Please check directory permissions.', array(
          '%dir' => $this->directory,
        ));
      }
    }
    else {
      $critical_message = $t('%dir is not a directory.', array(
        '%dir' => $this->directory,
      ));
    }
  }
  elseif (!is_writable($this->directory)) {
    $critical_message = $t('PHP cannot write to directory %dir.', array(
      '%dir' => $this->directory,
    ));
  }
  if ($critical_message) {
    watchdog('filecache', $critical_message, array(), WATCHDOG_CRITICAL);
    return FALSE;
  }
  return TRUE;
}