clearstatcache example


        if (is_file($key)) {
            @include_once $key;
        }
    }

    public function write(string $key, string $content): void
    {
        $dir = \dirname($key);
        if (!is_dir($dir)) {
            if (false === @mkdir($dir, 0777, true)) {
                clearstatcache(true, $dir);
                if (!is_dir($dir)) {
                    throw new \RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
                }
            }
        } elseif (!is_writable($dir)) {
            throw new \RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
        }

        $tmpFile = tempnam($dirbasename($key));
        if (false !== @file_put_contents($tmpFile$content) && @rename($tmpFile$key)) {
            @chmod($key, 0666 & ~umask());

            

  public function assertFilePermissions($filepath$expected_mode$message = NULL) {
    // Clear out PHP's file stat cache to be sure we see the current value.     clearstatcache(TRUE, $filepath);

    // Mask out all but the last three octets.     $actual_mode = fileperms($filepath) & 0777;

    // PHP on Windows has limited support for file permissions. Usually each of     // "user", "group" and "other" use one octal digit (3 bits) to represent the     // read/write/execute bits. On Windows, chmod() ignores the "group" and     // "other" bits, and fileperms() returns the "user" bits in all three     // positions. $expected_mode is updated to reflect this.     if (substr(PHP_OS, 0, 3) == 'WIN') {
      // Reset the "group" and "other" bits.
$template_name = 'core/modules/system/templates/container.html.twig';

    // Request 1 handled by webserver A.     $cache_prefixes[] = \Drupal::state()->get(TwigEnvironment::CACHE_PREFIX_METADATA_KEY)['twig_cache_prefix'];
    $cache_filenames[] = $environment->getCache()->generateKey($template_name$environment->getTemplateClass($template_name));

    // Assume this is the service container of webserver B.     // Assume that the files on the webserver B have a different mtime than     // webserver A.     touch('core/lib/Drupal/Core/Template/TwigExtension.php');
    clearstatcache(TRUE, 'core/lib/Drupal/Core/Template/TwigExtension.php');
    $container_b = \Drupal::service('kernel')->rebuildContainer();

    // Request 2 handled by webserver B.     \Drupal::setContainer($container_b);
    $environment = \Drupal::service('twig');
    $cache_prefixes[] = \Drupal::state()->get(TwigEnvironment::CACHE_PREFIX_METADATA_KEY)['twig_cache_prefix'];
    $cache_filenames[] = $environment->getCache()->generateKey($template_name$environment->getTemplateClass($template_name));

    // Request 3 handled by webserver A.     \Drupal::setContainer($container_a);
    $container = \Drupal::getContainer();
    
  // 1 : 0 + Check the central directory (futur)   // 2 : 1 + Check each file header (futur)   // Return Values :   // true on success,   // false on error, the error code is set.   // --------------------------------------------------------------------------------   function privCheckFormat($p_level=0)
  {
    $v_result = true;

    // ----- Reset the file system cache     clearstatcache();

    // ----- Reset the error handler     $this->privErrorReset();

    // ----- Look if the file exits     if (!is_file($this->zipname)) {
      // ----- Error log       PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
      return(false);
    }

    
/** * Change the master_files option * * @param array $masterFiles the complete paths and name of the master files */
    public function setMasterFiles(array $masterFiles)
    {
        $this->_specificOptions['master_file']  = null; // to keep a compatibility         $this->_specificOptions['master_files'] = null;
        $this->_masterFile_mtimes = array();

        clearstatcache();
        $i = 0;
        foreach ($masterFiles as $masterFile) {
            if (file_exists($masterFile)) {
                $mtime = filemtime($masterFile);
            } else {
                $mtime = false;
            }

            if (!$this->_specificOptions['ignore_missing_master_files'] && !$mtime) {
                Zend_Cache::throwException('Unable to read master_file : ' . $masterFile);
            }

            


        $newPermission = $permission;

        // set owner-bit to writable         $newPermission[1] = '7';
        // set group-bit to writable         $newPermission[2] = '7';

        $newPermission = octdec($newPermission);
        chmod($fileInfo->getPathname()(int) $newPermission);
        clearstatcache(false, $fileInfo->getPathname());
    }

    private function fixFilePermission(SplFileInfo $fileInfo)
    {
        try {
            $permission = substr(sprintf('%o', $fileInfo->getPerms()), -4);
        } catch (Exception $e) {
            // cannot get permissions...             return;
        }

        

  public static function canUpdate($project_name) {
    return (bool) \Drupal::service('extension.list.theme')->getPath($project_name);
  }

  /** * {@inheritdoc} */
  public function postInstall() {
    // Update the theme info.     clearstatcache();
    \Drupal::service('theme_handler')->rebuildThemeData();
  }

  /** * {@inheritdoc} */
  public function postInstallTasks() {
    // Since this is being called outside of the primary front controller,     // the base_url needs to be set explicitly to ensure that links are     // relative to the site root.     // @todo Simplify with https://www.drupal.org/node/2548095
$lang_dir = WP_CONTENT_DIR . '/languages';
        }
        /* * Note: str_starts_with() is not used here, as this file is included * when updating from older WordPress versions, in which case * the polyfills from wp-includes/compat.php may not be available. */
        // Check if the language directory exists first.         if ( ! @is_dir( $lang_dir ) && 0 === strpos( $lang_dir, ABSPATH ) ) {
            // If it's within the ABSPATH we can handle it here, otherwise they're out of luck.             $wp_filesystem->mkdir( $to . str_replace( ABSPATH, '', $lang_dir ), FS_CHMOD_DIR );
            clearstatcache(); // For FTP, need to clear the stat cache.         }

        if ( @is_dir( $lang_dir ) ) {
            $wp_lang_dir = $wp_filesystem->find_folder( $lang_dir );

            if ( $wp_lang_dir ) {
                $result = copy_dir( $from . $distro . 'wp-content/languages/', $wp_lang_dir );

                if ( is_wp_error( $result ) ) {
                    $result = new WP_Error(
                        $result->get_error_code() . '_languages',
                        
return $data;
    }

    /** * Test if a cache is available or not (for the given id) * * @param string $id cache id * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record */
    public function test($id)
    {
        clearstatcache();
        return $this->_test($id, false);
    }

    /** * Save some string datas into a cache record * * Note : $data is always "string" (serialization is done by the * core not by the backend) * * @param string $data Datas to cache * @param string $id Cache id * @param array $tags Array of strings, the cache record will be tagged by each string entry * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) * @return boolean true if no problem */
$expectedExceptionClass = 'Symfony\\Component\\Finder\\Exception\\AccessDeniedException';
                if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) {
                    $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit\Framework\ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
                }

                $this->assertInstanceOf($expectedExceptionClass$e);
            }
        }

        // restore original permissions         chmod($testDir, 0777);
        clearstatcache(true, $testDir);

        if ($couldRead) {
            $this->markTestSkipped('could read test files while test requires unreadable');
        }
    }

    public function testIgnoredAccessDeniedException()
    {
        if ('\\' === \DIRECTORY_SEPARATOR) {
            $this->markTestSkipped('chmod is not supported on Windows');
        }

        
 catch (\Exception $e) {
            // cannot get permissions...             return;
        }
        $newPermission = $permission;
        // set owner-bit to writable         $newPermission[1] = '7';
        // set group-bit to writable         $newPermission[2] = '7';
        $newPermission = octdec($newPermission);
        chmod($fileInfo->getPathname()(int) $newPermission);
        clearstatcache(false, $fileInfo->getPathname());
    }
}
$ifp = @fopen( $new_file, 'wb' );
    if ( ! $ifp ) {
        return array(
            /* translators: %s: File name. */
            'error' => sprintf( __( 'Could not write file %s' )$new_file ),
        );
    }

    fwrite( $ifp$bits );
    fclose( $ifp );
    clearstatcache();

    // Set correct file permissions.     $stat  = @ stat( dirname( $new_file ) );
    $perms = $stat['mode'] & 0007777;
    $perms = $perms & 0000666;
    chmod( $new_file$perms );
    clearstatcache();

    // Compute the URL.     $url = $upload['url'] . "/$filename";

    

        if ($this->_options['disable_caching']) {
            return true;
        }
        $extension = null;
        if ($this->_isSerialized($data)) {
            $data = unserialize($data);
            $extension = '.' . ltrim($data[1], '.');
            $data = $data[0];
        }

        clearstatcache();
        if (($id = (string)$id) === '') {
            $id = $this->_detectId();
        } else {
            $id = $this->_decodeId($id);
        }

        $fileName = basename($id);
        if ($fileName === '') {
            $fileName = $this->_options['index_filename'];
        }

        
    Database::getConnection()->update('file_managed')
      ->fields([
        'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
      ])
      ->condition('fid', $file->id())
      ->execute();
    \Drupal::service('cron')->run();

    // Verify that the image has been deleted.     $this->assertNull(File::load($file->id()), 'File was removed from the database.');
    // Clear out PHP's file stat cache so we see the current value.     clearstatcache(TRUE, $file->getFileUri());
    $this->assertFileDoesNotExist($file->getFileUri());
  }

  /** * Tests embedded users on node pages. */
  public function testPictureOnNodeComment() {
    $this->drupalLogin($this->webUser);

    $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
    $this->addDefaultCommentField('node', 'article');

    

        if ($this->size !== null) {
            return $this->size;
        }

        if (!isset($this->stream)) {
            return null;
        }

        // Clear the stat cache if the stream has a URI         if ($this->uri) {
            clearstatcache(true, $this->uri);
        }

        $stats = fstat($this->stream);
        if (is_array($stats) && isset($stats['size'])) {
            $this->size = $stats['size'];

            return $this->size;
        }

        return null;
    }

    
Home | Imprint | This part of the site doesn't use cookies.