Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
LockHandler.php
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
016 /**
017 * LockHandler class provides a simple abstraction to lock anything by means of
018 * a file lock.
019 *
020 * A locked file is created based on the lock name when calling lock(). Other
021 * lock handlers will not be able to lock the same name until it is released
022 * (explicitly by calling release() or implicitly when the instance holding the
023 * lock is destroyed).
024 *
025 * @author Grégoire Pineau <lyrixx@lyrixx.info>
026 * @author Romain Neutron <imprec@gmail.com>
027 * @author Nicolas Grekas <p@tchwork.com>
028 */
029 class LockHandler
030 {
031 private $file;
032 private $handle;
033
034 /**
035 * @param string $name The lock name
036 * @param string|null $lockPath The directory to store the lock. Default values will use temporary directory
037 *
038 * @throws IOException If the lock directory could not be created or is not writable
039 */
040 public function __construct($name, $lockPath = null)
041 {
042 $lockPath = $lockPath ?: sys_get_temp_dir();
043
044 if (!is_dir($lockPath)) {
045 $fs = new Filesystem();
046 $fs->mkdir($lockPath);
047 }
048
049 if (!is_writable($lockPath)) {
050 throw new IOException(sprintf('The directory "%s" is not writable.', $lockPath), 0, null, $lockPath);
051 }
052
053 $this->file = sprintf('%s/sf.%s.%s.lock', $lockPath, preg_replace('/[^a-z0-9\._-]+/i', '-', $name), hash('sha256', $name));
054 }
055
056 /**
057 * Lock the resource.
058 *
059 * @param bool $blocking wait until the lock is released
060 *
061 * @return bool Returns true if the lock was acquired, false otherwise
062 *
063 * @throws IOException If the lock file could not be created or opened
064 */
065 public function lock($blocking = false)
066 {
067 if ($this->handle) {
068 return true;
069 }
070
071 // Silence error reporting
072 set_error_handler(function () {});
073
074 if (!$this->handle = fopen($this->file, 'r')) {
075 if ($this->handle = fopen($this->file, 'x')) {
076 chmod($this->file, 0444);
077 } elseif (!$this->handle = fopen($this->file, 'r')) {
078 usleep(100); // Give some time for chmod() to complete
079 $this->handle = fopen($this->file, 'r');
080 }
081 }
082 restore_error_handler();
083
084 if (!$this->handle) {
085 $error = error_get_last();
086 throw new IOException($error['message'], 0, null, $this->file);
087 }
088
089 // On Windows, even if PHP doc says the contrary, LOCK_NB works, see
090 // https://bugs.php.net/54129
091 if (!flock($this->handle, LOCK_EX | ($blocking ? 0 : LOCK_NB))) {
092 fclose($this->handle);
093 $this->handle = null;
094
095 return false;
096 }
097
098 return true;
099 }
100
101 /**
102 * Release the resource.
103 */
104 public function release()
105 {
106 if ($this->handle) {
107 flock($this->handle, LOCK_UN | LOCK_NB);
108 fclose($this->handle);
109 $this->handle = null;
110 }
111 }
112 }
113