function drupal_verify_install_file

Same name in other branches
  1. 7.x includes/install.inc \drupal_verify_install_file()
  2. 8.9.x core/includes/install.inc \drupal_verify_install_file()
  3. 10 core/includes/install.inc \drupal_verify_install_file()
  4. 11.x core/includes/install.inc \drupal_verify_install_file()

Verifies the state of the specified file.

Parameters

$file: The file to check for.

$mask: An optional bitmask created from various FILE_* constants.

$type: The type of file. Can be file (default), dir, or link.

bool $autofix: (optional) Determines whether to attempt fixing the permissions according to the provided $mask. Defaults to TRUE.

Return value

bool TRUE on success or FALSE on failure. A message is set for the latter.

5 calls to drupal_verify_install_file()
install_check_requirements in core/includes/install.core.inc
Checks installation requirements and reports any errors.
install_check_translations in core/includes/install.core.inc
Checks installation requirements and reports any errors.
SiteConfigureForm::buildForm in core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php
Form constructor.
SitesDirectoryHardeningTest::testSitesDirectoryHardening in core/modules/system/tests/src/Functional/System/SitesDirectoryHardeningTest.php
Tests the default behavior to restrict directory permissions is enforced.
system_requirements in core/modules/system/system.install
Implements hook_requirements().

File

core/includes/install.inc, line 669

Code

function drupal_verify_install_file($file, $mask = NULL, $type = 'file', $autofix = TRUE) {
    $return = TRUE;
    // Check for files that shouldn't be there.
    if (isset($mask) && $mask & FILE_NOT_EXIST && file_exists($file)) {
        return FALSE;
    }
    // Verify that the file is the type of file it is supposed to be.
    if (isset($type) && file_exists($file)) {
        $check = 'is_' . $type;
        if (!function_exists($check) || !$check($file)) {
            $return = FALSE;
        }
    }
    // Verify file permissions.
    if (isset($mask)) {
        $masks = [
            FILE_EXIST,
            FILE_READABLE,
            FILE_WRITABLE,
            FILE_EXECUTABLE,
            FILE_NOT_READABLE,
            FILE_NOT_WRITABLE,
            FILE_NOT_EXECUTABLE,
        ];
        foreach ($masks as $current_mask) {
            if ($mask & $current_mask) {
                switch ($current_mask) {
                    case FILE_EXIST:
                        if (!file_exists($file)) {
                            if ($type == 'dir' && $autofix) {
                                drupal_install_mkdir($file, $mask);
                            }
                            if (!file_exists($file)) {
                                $return = FALSE;
                            }
                        }
                        break;
                    case FILE_READABLE:
                        if (!is_readable($file)) {
                            $return = FALSE;
                        }
                        break;
                    case FILE_WRITABLE:
                        if (!is_writable($file)) {
                            $return = FALSE;
                        }
                        break;
                    case FILE_EXECUTABLE:
                        if (!is_executable($file)) {
                            $return = FALSE;
                        }
                        break;
                    case FILE_NOT_READABLE:
                        if (is_readable($file)) {
                            $return = FALSE;
                        }
                        break;
                    case FILE_NOT_WRITABLE:
                        if (is_writable($file)) {
                            $return = FALSE;
                        }
                        break;
                    case FILE_NOT_EXECUTABLE:
                        if (is_executable($file)) {
                            $return = FALSE;
                        }
                        break;
                }
            }
        }
    }
    if (!$return && $autofix) {
        return drupal_install_fix_file($file, $mask);
    }
    return $return;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.