diff options
Diffstat (limited to '3rdparty/Sabre/DAV/Locks/Backend/File.php')
-rwxr-xr-x[-rw-r--r--] | 3rdparty/Sabre/DAV/Locks/Backend/File.php | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/3rdparty/Sabre/DAV/Locks/Backend/File.php b/3rdparty/Sabre/DAV/Locks/Backend/File.php index f65b20c4306..c33f963514b 100644..100755 --- a/3rdparty/Sabre/DAV/Locks/Backend/File.php +++ b/3rdparty/Sabre/DAV/Locks/Backend/File.php @@ -3,30 +3,30 @@ /** * The Lock manager allows you to handle all file-locks centrally. * - * This Lock Manager stores all its data in a single file. + * This Lock Manager stores all its data in a single file. * * Note that this is not nearly as robust as a database, you are encouraged * to use the PDO backend instead. * * @package Sabre * @subpackage DAV - * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved. - * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License */ class Sabre_DAV_Locks_Backend_File extends Sabre_DAV_Locks_Backend_Abstract { /** * The storage file - * - * @var string + * + * @var string */ private $locksFile; /** * Constructor * - * @param string $locksFile path to file + * @param string $locksFile path to file */ public function __construct($locksFile) { @@ -35,24 +35,24 @@ class Sabre_DAV_Locks_Backend_File extends Sabre_DAV_Locks_Backend_Abstract { } /** - * Returns a list of Sabre_DAV_Locks_LockInfo objects - * + * Returns a list of Sabre_DAV_Locks_LockInfo objects + * * This method should return all the locks for a particular uri, including * locks that might be set on a parent uri. * * If returnChildLocks is set to true, this method should also look for * any locks in the subtree of the uri for locks. * - * @param string $uri + * @param string $uri * @param bool $returnChildLocks - * @return array + * @return array */ public function getLocks($uri, $returnChildLocks) { $newLocks = array(); - $currentPath = ''; $locks = $this->getData(); + foreach($locks as $lock) { if ($lock->uri === $uri || @@ -70,29 +70,35 @@ class Sabre_DAV_Locks_Backend_File extends Sabre_DAV_Locks_Backend_Abstract { // Checking if we can remove any of these locks foreach($newLocks as $k=>$lock) { - if (time() > $lock->timeout + $lock->created) unset($newLocks[$k]); + if (time() > $lock->timeout + $lock->created) unset($newLocks[$k]); } return $newLocks; } /** - * Locks a uri - * - * @param string $uri - * @param Sabre_DAV_Locks_LockInfo $lockInfo - * @return bool + * Locks a uri + * + * @param string $uri + * @param Sabre_DAV_Locks_LockInfo $lockInfo + * @return bool */ - public function lock($uri,Sabre_DAV_Locks_LockInfo $lockInfo) { + public function lock($uri, Sabre_DAV_Locks_LockInfo $lockInfo) { // We're making the lock timeout 30 minutes $lockInfo->timeout = 1800; $lockInfo->created = time(); $lockInfo->uri = $uri; - $locks = $this->getLocks($uri,false); + $locks = $this->getData(); + foreach($locks as $k=>$lock) { - if ($lock->token == $lockInfo->token) unset($locks[$k]); + if ( + ($lock->token == $lockInfo->token) || + (time() > $lock->timeout + $lock->created) + ) { + unset($locks[$k]); + } } $locks[] = $lockInfo; $this->putData($locks); @@ -101,15 +107,15 @@ class Sabre_DAV_Locks_Backend_File extends Sabre_DAV_Locks_Backend_Abstract { } /** - * Removes a lock from a uri - * - * @param string $uri - * @param Sabre_DAV_Locks_LockInfo $lockInfo - * @return bool + * Removes a lock from a uri + * + * @param string $uri + * @param Sabre_DAV_Locks_LockInfo $lockInfo + * @return bool */ - public function unlock($uri,Sabre_DAV_Locks_LockInfo $lockInfo) { + public function unlock($uri, Sabre_DAV_Locks_LockInfo $lockInfo) { - $locks = $this->getLocks($uri,false); + $locks = $this->getData(); foreach($locks as $k=>$lock) { if ($lock->token == $lockInfo->token) { @@ -127,7 +133,7 @@ class Sabre_DAV_Locks_Backend_File extends Sabre_DAV_Locks_Backend_Abstract { /** * Loads the lockdata from the filesystem. * - * @return array + * @return array */ protected function getData() { @@ -153,7 +159,7 @@ class Sabre_DAV_Locks_Backend_File extends Sabre_DAV_Locks_Backend_Abstract { /** * Saves the lockdata * - * @param array $newData + * @param array $newData * @return void */ protected function putData(array $newData) { |