You are here

function _google_tag_is_executable in GoogleTagManager 8

Same name and namespace in other branches
  1. 7.2 google_tag.module \_google_tag_is_executable()
  2. 7 includes/admin.inc \_google_tag_is_executable()

Determines whether a directory is searchable.

Remove this if PHP is_executable() is changed to not return FALSE simply because the URI points to a directory (not a file) in a stream wrapper other than the local file wrapper provided by PHP.

Parameters

string $uri: A directory path or stream wrapper URI.

Return value

bool Whether the directory is searchable.

4 calls to _google_tag_is_executable()
ContainerManager::createAssets in src/Entity/ContainerManager.php
Prepares directory for and saves snippet files for a container.
ContainerTrait::validateFormValues in src/Form/ContainerTrait.php
google_tag_requirements in ./google_tag.install
Implements hook_requirements().
_file_prepare_directory in ./google_tag.module
Checks that the directory exists and is writable.

File

./google_tag.module, line 174
Provides primary Drupal hook implementations.

Code

function _google_tag_is_executable($uri) {
  if ($realpath = \Drupal::service('file_system')
    ->realpath($uri)) {

    // The URI is a local stream wrapper or a local path.
    // Use the local path since PHP only checks ACLs on its local file wrapper.
    // Remove the OS check if PHP is_executable() is changed to not return FALSE
    // simply because the URI points to a directory (not a file) on Windows.
    return _google_tag_is_windows() || is_executable($realpath);
  }
  if ($wrapper = \Drupal::service('stream_wrapper_manager')
    ->getViaUri($uri)) {

    // The URI is a remote stream wrapper.
    if (!($stat = $wrapper
      ->url_stat($uri, 0))) {
      return FALSE;
    }
    if (!function_exists('posix_getuid') || !function_exists('posix_getgid')) {

      // These functions are never defined on Windows and the extension that
      // provides them may not be included on a Linux distribution.
      // If directory is not searchable, then fault the site deployment process.
      // @todo Is it worse to return true or false at this point?
      return TRUE;
    }

    // Determine the appropriate permissions bit mask as an octal.
    // The stat array is likely to have uid=gid=0 so that the mask is octal 01.
    // This is true for Amazon S3 and Google Cloud Storage.
    $mask = 1;
    if ($stat['uid'] == posix_getuid()) {
      $mask = $mask << 6;
    }
    elseif ($stat['gid'] == posix_getgid()) {
      $mask = $mask << 3;
    }
    return ($stat['mode'] & $mask) != 0;
  }
  return FALSE;
}