Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

LockHandler.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 3.81 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\Filesystem;
013   
014  use Symfony\Component\Filesystem\Exception\IOException;
015  use Symfony\Component\Lock\Store\FlockStore;
016  use Symfony\Component\Lock\Store\SemaphoreStore;
017   
018  @trigger_error(sprintf('The %s class is deprecated since Symfony 3.4 and will be removed in 4.0. Use %s or %s instead.', LockHandler::class, SemaphoreStore::class, FlockStore::class), \E_USER_DEPRECATED);
019   
020  /**
021   * LockHandler class provides a simple abstraction to lock anything by means of
022   * a file lock.
023   *
024   * A locked file is created based on the lock name when calling lock(). Other
025   * lock handlers will not be able to lock the same name until it is released
026   * (explicitly by calling release() or implicitly when the instance holding the
027   * lock is destroyed).
028   *
029   * @author Grégoire Pineau <lyrixx@lyrixx.info>
030   * @author Romain Neutron <imprec@gmail.com>
031   * @author Nicolas Grekas <p@tchwork.com>
032   *
033   * @deprecated since version 3.4, to be removed in 4.0. Use Symfony\Component\Lock\Store\SemaphoreStore or Symfony\Component\Lock\Store\FlockStore instead.
034   */
035  class LockHandler
036  {
037      private $file;
038      private $handle;
039   
040      /**
041       * @param string      $name     The lock name
042       * @param string|null $lockPath The directory to store the lock. Default values will use temporary directory
043       *
044       * @throws IOException If the lock directory could not be created or is not writable
045       */
046      public function __construct($name, $lockPath = null)
047      {
048          $lockPath = $lockPath ?: sys_get_temp_dir();
049   
050          if (!is_dir($lockPath)) {
051              $fs = new Filesystem();
052              $fs->mkdir($lockPath);
053          }
054   
055          if (!is_writable($lockPath)) {
056              throw new IOException(sprintf('The directory "%s" is not writable.', $lockPath), 0, null, $lockPath);
057          }
058   
059          $this->file = sprintf('%s/sf.%s.%s.lock', $lockPath, preg_replace('/[^a-z0-9\._-]+/i', '-', $name), hash('sha256', $name));
060      }
061   
062      /**
063       * Lock the resource.
064       *
065       * @param bool $blocking Wait until the lock is released
066       *
067       * @return bool Returns true if the lock was acquired, false otherwise
068       *
069       * @throws IOException If the lock file could not be created or opened
070       */
071      public function lock($blocking = false)
072      {
073          if ($this->handle) {
074              return true;
075          }
076   
077          $error = null;
078   
079          // Silence error reporting
080          set_error_handler(function ($errno, $msg) use (&$error) {
081              $error = $msg;
082          });
083   
084          if (!$this->handle = fopen($this->file, 'r+') ?: fopen($this->file, 'r')) {
085              if ($this->handle = fopen($this->file, 'x')) {
086                  chmod($this->file, 0666);
087              } elseif (!$this->handle = fopen($this->file, 'r+') ?: fopen($this->file, 'r')) {
088                  usleep(100); // Give some time for chmod() to complete
089                  $this->handle = fopen($this->file, 'r+') ?: fopen($this->file, 'r');
090              }
091          }
092          restore_error_handler();
093   
094          if (!$this->handle) {
095              throw new IOException($error, 0, null, $this->file);
096          }
097   
098          // On Windows, even if PHP doc says the contrary, LOCK_NB works, see
099          // https://bugs.php.net/54129
100          if (!flock($this->handle, \LOCK_EX | ($blocking ? 0 : \LOCK_NB))) {
101              fclose($this->handle);
102              $this->handle = null;
103   
104              return false;
105          }
106   
107          return true;
108      }
109   
110      /**
111       * Release the resource.
112       */
113      public function release()
114      {
115          if ($this->handle) {
116              flock($this->handle, \LOCK_UN | \LOCK_NB);
117              fclose($this->handle);
118              $this->handle = null;
119          }
120      }
121  }
122