[Pkg-owncloud-commits] [owncloud] 23/205: Lock file before download

David Prévot taffit at moszumanska.debian.org
Thu Jul 2 17:36:50 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit a9bca9e3aa58feb1d8c6a1f8fdd15e3a7c436650
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Wed Jun 17 17:40:46 2015 +0200

    Lock file before download
    
    This will throw a LockedException if a concurrent request is currently
    touching that file.
---
 lib/private/files.php | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/private/files.php b/lib/private/files.php
index 5a3e102..90d83a1 100644
--- a/lib/private/files.php
+++ b/lib/private/files.php
@@ -43,6 +43,8 @@
 // TODO: get rid of this using proper composer packages
 require_once 'mcnetic/phpzipstreamer/ZipStreamer.php';
 
+use OCP\Lock\ILockingProvider;
+
 /**
  * Class for file server access
  *
@@ -82,6 +84,7 @@ class OC_Files {
 	 * @param boolean $only_header ; boolean to only send header of the request
 	 */
 	public static function get($dir, $files, $only_header = false) {
+		$view = \OC\Files\Filesystem::getView();
 		$xsendfile = false;
 		if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) ||
 			isset($_SERVER['MOD_X_SENDFILE2_ENABLED']) ||
@@ -131,7 +134,9 @@ class OC_Files {
 		OC_Util::obEnd();
 
 		try {
-
+			if ($get_type === self::FILE) {
+				$view->lockFile($filename, ILockingProvider::LOCK_SHARED);
+			}
 			if ($zip or \OC\Files\Filesystem::isReadable($filename)) {
 				self::sendHeaders($filename, $name, $zip);
 			} elseif (!\OC\Files\Filesystem::file_exists($filename)) {
@@ -168,7 +173,6 @@ class OC_Files {
 				set_time_limit($executionTime);
 			} else {
 				if ($xsendfile) {
-					$view = \OC\Files\Filesystem::getView();
 					/** @var $storage \OC\Files\Storage\Storage */
 					list($storage) = $view->resolvePath($filename);
 					if ($storage->isLocal()) {
@@ -180,6 +184,13 @@ class OC_Files {
 					\OC\Files\Filesystem::readfile($filename);
 				}
 			}
+			if ($get_type === self::FILE) {
+				$view->unlockFile($filename, ILockingProvider::LOCK_SHARED);
+			}
+		} catch (\OCP\Lock\LockedException $ex) {
+			$l = \OC::$server->getL10N('core');
+			$hint = method_exists($ex, 'getHint') ? $ex->getHint() : '';
+			\OC_Template::printErrorPage($l->t('File is currently busy, please try again later'), $hint);
 		} catch (\Exception $ex) {
 			$l = \OC::$server->getL10N('core');
 			$hint = method_exists($ex, 'getHint') ? $ex->getHint() : '';

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list