Merge pull request #17009 from owncloud/lock-downloadfile

Lock file during download
This commit is contained in:
Thomas Müller 2015-06-26 13:04:34 +02:00
commit 796aae4402
1 changed files with 21 additions and 6 deletions

View File

@ -43,6 +43,9 @@
// TODO: get rid of this using proper composer packages // TODO: get rid of this using proper composer packages
require_once 'mcnetic/phpzipstreamer/ZipStreamer.php'; require_once 'mcnetic/phpzipstreamer/ZipStreamer.php';
use OC\Lock\NoopLockingProvider;
use OCP\Lock\ILockingProvider;
/** /**
* Class for file server access * Class for file server access
* *
@ -82,12 +85,16 @@ class OC_Files {
* @param boolean $only_header ; boolean to only send header of the request * @param boolean $only_header ; boolean to only send header of the request
*/ */
public static function get($dir, $files, $only_header = false) { public static function get($dir, $files, $only_header = false) {
$view = \OC\Files\Filesystem::getView();
$xsendfile = false; $xsendfile = false;
if (\OC::$server->getLockingProvider() instanceof NoopLockingProvider) {
if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) ||
isset($_SERVER['MOD_X_SENDFILE2_ENABLED']) || isset($_SERVER['MOD_X_SENDFILE2_ENABLED']) ||
isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])
) {
$xsendfile = true; $xsendfile = true;
} }
}
if (is_array($files) && count($files) === 1) { if (is_array($files) && count($files) === 1) {
$files = $files[0]; $files = $files[0];
@ -131,7 +138,9 @@ class OC_Files {
OC_Util::obEnd(); OC_Util::obEnd();
try { try {
if ($get_type === self::FILE) {
$view->lockFile($filename, ILockingProvider::LOCK_SHARED);
}
if ($zip or \OC\Files\Filesystem::isReadable($filename)) { if ($zip or \OC\Files\Filesystem::isReadable($filename)) {
self::sendHeaders($filename, $name, $zip); self::sendHeaders($filename, $name, $zip);
} elseif (!\OC\Files\Filesystem::file_exists($filename)) { } elseif (!\OC\Files\Filesystem::file_exists($filename)) {
@ -168,7 +177,6 @@ class OC_Files {
set_time_limit($executionTime); set_time_limit($executionTime);
} else { } else {
if ($xsendfile) { if ($xsendfile) {
$view = \OC\Files\Filesystem::getView();
/** @var $storage \OC\Files\Storage\Storage */ /** @var $storage \OC\Files\Storage\Storage */
list($storage) = $view->resolvePath($filename); list($storage) = $view->resolvePath($filename);
if ($storage->isLocal()) { if ($storage->isLocal()) {
@ -180,6 +188,13 @@ class OC_Files {
\OC\Files\Filesystem::readfile($filename); \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) { } catch (\Exception $ex) {
$l = \OC::$server->getL10N('core'); $l = \OC::$server->getL10N('core');
$hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; $hint = method_exists($ex, 'getHint') ? $ex->getHint() : '';