Skip to content

Commit

Permalink
Merge pull request #17009 from owncloud/lock-downloadfile
Browse files Browse the repository at this point in the history
Lock file during download
  • Loading branch information
DeepDiver1975 committed Jun 26, 2015
2 parents 9558562 + c74c8ef commit 796aae4
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions lib/private/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
// TODO: get rid of this using proper composer packages
require_once 'mcnetic/phpzipstreamer/ZipStreamer.php';

use OC\Lock\NoopLockingProvider;
use OCP\Lock\ILockingProvider;

/**
* Class for file server access
*
Expand Down Expand Up @@ -82,11 +85,15 @@ private static function sendHeaders($filename, $name, $zip = false) {
* @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']) ||
isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) {
$xsendfile = true;
if (\OC::$server->getLockingProvider() instanceof NoopLockingProvider) {
if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) ||
isset($_SERVER['MOD_X_SENDFILE2_ENABLED']) ||
isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])
) {
$xsendfile = true;
}
}

if (is_array($files) && count($files) === 1) {
Expand Down Expand Up @@ -131,7 +138,9 @@ public static function get($dir, $files, $only_header = false) {
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)) {
Expand Down Expand Up @@ -168,7 +177,6 @@ public static function get($dir, $files, $only_header = false) {
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()) {
Expand All @@ -180,6 +188,13 @@ public static function get($dir, $files, $only_header = false) {
\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() : '';
Expand Down

0 comments on commit 796aae4

Please sign in to comment.