Skip to content
Snippets Groups Projects
Select Git revision
  • ba887d2b171a410e2c5925fa9e1519e7e69b71c2
  • master default protected
2 results

lock.php

Blame
  • lock.php 10.08 KiB
    <?php
    /**
     *
     * This library is free software; you can redistribute it and/or
     * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
     * License as published by the Free Software Foundation; either
     * version 3 of the License, or any later version.
     *
     * This library is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
     *
     * You should have received a copy of the GNU Affero General Public
     * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
     *
     */
    
    namespace OC\Files;
    
    use OCP\Config;
    use OC\Files\Filesystem;
    use OCP\Files\LockNotAcquiredException;
    
    /**
     * Class Lock
     * @package OC\Files
     */
    class Lock implements \OCP\Files\Lock {
    
    	/** @var int $retries Number of lock retries to attempt */
    	public static $retries = 40;
    
    	/** @var int $retryInterval Milliseconds between retries */
    	public static $retryInterval = 50;
    
    	/** @var string $path Filename of the file as represented in storage */
    	protected $path;
    
    	/** @var array $stack A stack of lock data */
    	protected $stack = array();
    
    	/** @var resource $handle A file handle used to maintain a lock  */
    	protected $handle;
    
    	/** @var string $lockFile Filename of the lock file */
    	protected $lockFile;
    
    	/** @var resource $lockFileHandle The file handle used to maintain a lock on the lock file */
    	protected $lockFileHandle;
    
    	/**
    	 * Constructor for the lock instance
    	 * @param string $path Absolute pathname for a local file on which to obtain a lock
    	 */
    	public function __construct($path) {
    		$this->path = Filesystem::normalizePath($path);
    	}
    
    	protected function obtainReadLock($existingHandle = null) {
    		\OC_Log::write('lock', sprintf('INFO: Read lock requested for %s', $this->path), \OC_Log::DEBUG);
    		$timeout = Lock::$retries;
    
    		// Re-use an existing handle or get a new one
    		if(empty($existingHandle)) {
    			$handle = fopen($this->path, 'r');
    		}
    		else {
    			$handle = $existingHandle;
    		}