Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-11-14 23:57:29 +0400
committerThomas Müller <thomas.mueller@tmit.eu>2013-11-14 23:57:29 +0400
commit617dc0e468cd285a28f337c565f9f9ae1aa2e85f (patch)
treed239833a66fb38a5f46f0b5bdb353ff478e267ca /lib
parent99ee95d46c3e14cb902493df3201a2c1ad9d6dc5 (diff)
parentecc7b01cee466d4893f8199abaee363c6bc4dac9 (diff)
Merge branch 'master' into moviepreviewfallback
Conflicts: lib/private/preview/movies.php
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php13
-rw-r--r--lib/l10n/uz.php8
-rw-r--r--lib/private/api.php71
-rw-r--r--lib/private/connector/sabre/file.php28
-rw-r--r--lib/private/files/cache/homecache.php40
-rw-r--r--lib/private/files/cache/scanner.php5
-rw-r--r--lib/private/files/cache/watcher.php9
-rw-r--r--lib/private/files/filesystem.php34
-rw-r--r--lib/private/files/storage/common.php10
-rw-r--r--lib/private/files/storage/home.php21
-rw-r--r--lib/private/preview/image.php4
-rw-r--r--lib/private/preview/movies.php3
-rw-r--r--lib/private/preview/mp3.php6
-rw-r--r--lib/private/preview/office-cl.php3
-rw-r--r--lib/private/preview/office-fallback.php3
-rw-r--r--lib/private/setup.php15
-rw-r--r--lib/public/share.php2
17 files changed, 222 insertions, 53 deletions
diff --git a/lib/base.php b/lib/base.php
index 4f8d97ac95d..f3983a3800f 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -308,14 +308,9 @@ class OC {
self::$session = new \OC\Session\Internal(OC_Util::getInstanceId());
// if session cant be started break with http 500 error
} catch (Exception $e) {
- OC_Log::write('core', 'Session could not be initialized. Exception message: '.$e->getMessage(),
- OC_Log::ERROR);
- header('HTTP/1.1 500 Internal Server Error');
- OC_Util::addStyle("styles");
- $error = 'Session could not be initialized. Please contact your ';
- $error .= 'system administrator.';
-
- OC_Template::printErrorPage($error);
+ //show the user a detailed error page
+ OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
+ OC_Template::printExceptionErrorPage($e);
}
$sessionLifeTime = self::getSessionLifeTime();
@@ -624,6 +619,8 @@ class OC {
public static function registerPreviewHooks() {
OC_Hook::connect('OC_Filesystem', 'post_write', 'OC\Preview', 'post_write');
OC_Hook::connect('OC_Filesystem', 'delete', 'OC\Preview', 'post_delete');
+ OC_Hook::connect('\OCP\Versions', 'delete', 'OC\Preview', 'post_delete');
+ OC_Hook::connect('\OCP\Trashbin', 'delete', 'OC\Preview', 'post_delete');
}
/**
diff --git a/lib/l10n/uz.php b/lib/l10n/uz.php
new file mode 100644
index 00000000000..e7b09649a24
--- /dev/null
+++ b/lib/l10n/uz.php
@@ -0,0 +1,8 @@
+<?php
+$TRANSLATIONS = array(
+"_%n minute ago_::_%n minutes ago_" => array(""),
+"_%n hour ago_::_%n hours ago_" => array(""),
+"_%n day go_::_%n days ago_" => array(""),
+"_%n month ago_::_%n months ago_" => array("")
+);
+$PLURAL_FORMS = "nplurals=1; plural=0;";
diff --git a/lib/private/api.php b/lib/private/api.php
index 7e69a6a77d2..03d7b7382a5 100644
--- a/lib/private/api.php
+++ b/lib/private/api.php
@@ -96,6 +96,7 @@ class OC_API {
$responses[] = array(
'app' => $action['app'],
'response' => new OC_OCS_Result(null, OC_API::RESPOND_UNAUTHORISED, 'Unauthorised'),
+ 'shipped' => OC_App::isShipped($action['app']),
);
continue;
}
@@ -103,6 +104,7 @@ class OC_API {
$responses[] = array(
'app' => $action['app'],
'response' => new OC_OCS_Result(null, OC_API::RESPOND_NOT_FOUND, 'Api method not found'),
+ 'shipped' => OC_App::isShipped($action['app']),
);
continue;
}
@@ -110,6 +112,7 @@ class OC_API {
$responses[] = array(
'app' => $action['app'],
'response' => call_user_func($action['action'], $parameters),
+ 'shipped' => OC_App::isShipped($action['app']),
);
}
$response = self::mergeResponses($responses);
@@ -127,7 +130,7 @@ class OC_API {
* merge the returned result objects into one response
* @param array $responses
*/
- private static function mergeResponses($responses) {
+ public static function mergeResponses($responses) {
$response = array();
// Sort into shipped and thirdparty
$shipped = array(
@@ -140,50 +143,76 @@ class OC_API {
);
foreach($responses as $response) {
- if(OC_App::isShipped($response['app']) || ($response['app'] === 'core')) {
+ if($response['shipped'] || ($response['app'] === 'core')) {
if($response['response']->succeeded()) {
- $shipped['succeeded'][$response['app']] = $response['response'];
+ $shipped['succeeded'][$response['app']] = $response;
} else {
- $shipped['failed'][$response['app']] = $response['response'];
+ $shipped['failed'][$response['app']] = $response;
}
} else {
if($response['response']->succeeded()) {
- $thirdparty['succeeded'][$response['app']] = $response['response'];
+ $thirdparty['succeeded'][$response['app']] = $response;
} else {
- $thirdparty['failed'][$response['app']] = $response['response'];
+ $thirdparty['failed'][$response['app']] = $response;
}
}
}
// Remove any error responses if there is one shipped response that succeeded
- if(!empty($shipped['succeeded'])) {
- $responses = array_merge($shipped['succeeded'], $thirdparty['succeeded']);
- } else if(!empty($shipped['failed'])) {
+ if(!empty($shipped['failed'])) {
// Which shipped response do we use if they all failed?
// They may have failed for different reasons (different status codes)
// Which reponse code should we return?
// Maybe any that are not OC_API::RESPOND_SERVER_ERROR
- $response = reset($shipped['failed']);
+ // Merge failed responses if more than one
+ $data = array();
+ $meta = array();
+ foreach($shipped['failed'] as $failure) {
+ $data = array_merge_recursive($data, $failure['response']->getData());
+ }
+ $picked = reset($shipped['failed']);
+ $code = $picked['response']->getStatusCode();
+ $response = new OC_OCS_Result($data, $code);
return $response;
+ } elseif(!empty($shipped['succeeded'])) {
+ $responses = array_merge($shipped['succeeded'], $thirdparty['succeeded']);
} elseif(!empty($thirdparty['failed'])) {
- // Return the third party failure result
- $response = reset($thirdparty['failed']);
+ // Merge failed responses if more than one
+ $data = array();
+ $meta = array();
+ foreach($thirdparty['failed'] as $failure) {
+ $data = array_merge_recursive($data, $failure['response']->getData());
+ }
+ $picked = reset($thirdparty['failed']);
+ $code = $picked['response']->getStatusCode();
+ $response = new OC_OCS_Result($data, $code);
return $response;
} else {
- $responses = array_merge($shipped['succeeded'], $thirdparty['succeeded']);
+ $responses = $thirdparty['succeeded'];
}
// Merge the successful responses
$meta = array();
$data = array();
foreach($responses as $app => $response) {
- if(OC_App::isShipped($app)) {
- $data = array_merge_recursive($response->getData(), $data);
+ if($response['shipped']) {
+ $data = array_merge_recursive($response['response']->getData(), $data);
} else {
- $data = array_merge_recursive($data, $response->getData());
+ $data = array_merge_recursive($data, $response['response']->getData());
+ }
+ $codes[] = $response['response']->getStatusCode();
+ }
+
+ // Use any non 100 status codes
+ $statusCode = 100;
+ foreach($codes as $code) {
+ if($code != 100) {
+ $statusCode = $code;
+ break;
}
}
- $result = new OC_OCS_Result($data, 100);
+
+ $result = new OC_OCS_Result($data, $statusCode);
return $result;
}
@@ -245,6 +274,10 @@ class OC_API {
$return = OC_User::login($authUser, $authPw);
if ($return === true) {
self::$logoutRequired = true;
+
+ // initialize the user's filesystem
+ \OC_Util::setUpFS(\OC_User::getUser());
+
return $authUser;
}
@@ -252,6 +285,10 @@ class OC_API {
$loggedIn = OC_User::isLoggedIn();
$ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
if ($loggedIn === true && $ocsApiRequest) {
+
+ // initialize the user's filesystem
+ \OC_Util::setUpFS(\OC_User::getUser());
+
return OC_User::getUser();
}
diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php
index 919bb1fc6f4..26b5d200bde 100644
--- a/lib/private/connector/sabre/file.php
+++ b/lib/private/connector/sabre/file.php
@@ -230,9 +230,31 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
}
if ($chunk_handler->isComplete()) {
- $newPath = $path . '/' . $info['name'];
- $chunk_handler->file_assemble($newPath);
- return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
+
+ // we first assembly the target file as a part file
+ $partFile = $path . '/' . $info['name'] . '.ocTransferId' . $info['transferid'] . '.part';
+ $chunk_handler->file_assemble($partFile);
+
+ // here is the final atomic rename
+ $fs = $this->getFS();
+ $targetPath = $path . '/' . $info['name'];
+ $renameOkay = $fs->rename($partFile, $targetPath);
+ $fileExists = $fs->file_exists($targetPath);
+ if ($renameOkay === false || $fileExists === false) {
+ \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
+ $fs->unlink($targetPath);
+ throw new Sabre_DAV_Exception();
+ }
+
+ // allow sync clients to send the mtime along in a header
+ $mtime = OC_Request::hasModificationTime();
+ if ($mtime !== false) {
+ if($fs->touch($this->path, $mtime)) {
+ header('X-OC-MTime: accepted');
+ }
+ }
+
+ return OC_Connector_Sabre_Node::getETagPropertyForPath($targetPath);
}
return null;
diff --git a/lib/private/files/cache/homecache.php b/lib/private/files/cache/homecache.php
new file mode 100644
index 00000000000..4b14bd12190
--- /dev/null
+++ b/lib/private/files/cache/homecache.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Cache;
+
+class HomeCache extends Cache {
+ /**
+ * get the size of a folder and set it in the cache
+ *
+ * @param string $path
+ * @return int
+ */
+ public function calculateFolderSize($path) {
+ if ($path !== '/' and $path !== '') {
+ return parent::calculateFolderSize($path);
+ }
+
+ $totalSize = 0;
+ $entry = $this->get($path);
+ if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
+ $id = $entry['fileid'];
+ $sql = 'SELECT SUM(`size`) FROM `*PREFIX*filecache` ' .
+ 'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
+ $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
+ if ($row = $result->fetchRow()) {
+ list($sum) = array_values($row);
+ $totalSize = (int)$sum;
+ if ($entry['size'] !== $totalSize) {
+ $this->update($id, array('size' => $totalSize));
+ }
+ }
+ }
+ return $totalSize;
+ }
+}
diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php
index 17f99d675ae..34184c68c64 100644
--- a/lib/private/files/cache/scanner.php
+++ b/lib/private/files/cache/scanner.php
@@ -17,6 +17,8 @@ use OC\Hooks\BasicEmitter;
* Hooks available in scope \OC\Files\Cache\Scanner:
* - scanFile(string $path, string $storageId)
* - scanFolder(string $path, string $storageId)
+ * - postScanFile(string $path, string $storageId)
+ * - postScanFolder(string $path, string $storageId)
*
* @package OC\Files\Cache
*/
@@ -154,6 +156,8 @@ class Scanner extends BasicEmitter {
}
if (!empty($newData)) {
$this->cache->put($file, $newData);
+ $this->emit('\OC\Files\Cache\Scanner', 'postScanFile', array($file, $this->storageId));
+ \OC_Hook::emit('\OC\Files\Cache\Scanner', 'post_scan_file', array('path' => $file, 'storage' => $this->storageId));
}
} else {
$this->cache->remove($file);
@@ -258,6 +262,7 @@ class Scanner extends BasicEmitter {
}
$this->cache->put($path, array('size' => $size));
}
+ $this->emit('\OC\Files\Cache\Scanner', 'postScanFolder', array($path, $this->storageId));
return $size;
}
diff --git a/lib/private/files/cache/watcher.php b/lib/private/files/cache/watcher.php
index 8bfd4602f3a..58f624c8990 100644
--- a/lib/private/files/cache/watcher.php
+++ b/lib/private/files/cache/watcher.php
@@ -15,17 +15,17 @@ class Watcher {
/**
* @var \OC\Files\Storage\Storage $storage
*/
- private $storage;
+ protected $storage;
/**
* @var Cache $cache
*/
- private $cache;
+ protected $cache;
/**
* @var Scanner $scanner;
*/
- private $scanner;
+ protected $scanner;
/**
* @param \OC\Files\Storage\Storage $storage
@@ -40,6 +40,7 @@ class Watcher {
* check $path for updates
*
* @param string $path
+ * @return boolean true if path was updated, false otherwise
*/
public function checkUpdate($path) {
$cachedEntry = $this->cache->get($path);
@@ -53,7 +54,9 @@ class Watcher {
$this->cleanFolder($path);
}
$this->cache->correctFolderSize($path);
+ return true;
}
+ return false;
}
/**
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index e40502bbe64..8500b3c581b 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -307,10 +307,18 @@ class Filesystem {
$root = \OC_User::getHome($user);
$userObject = \OC_User::getManager()->get($user);
- if (\OC\Files\Cache\Storage::exists('local::' . $root . '/') or is_null($userObject)) {
+
+ if (!is_null($userObject)) {
+ // check for legacy home id (<= 5.0.12)
+ if (\OC\Files\Cache\Storage::exists('local::' . $root . '/')) {
+ self::mount('\OC\Files\Storage\Home', array('user' => $userObject, 'legacy' => true), $user);
+ }
+ else {
+ self::mount('\OC\Files\Storage\Home', array('user' => $userObject), $user);
+ }
+ }
+ else {
self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user);
- } else {
- self::mount('\OC\Files\Storage\Home', array('user' => $userObject), $user);
}
$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
@@ -681,18 +689,32 @@ class Filesystem {
}
//no windows style slashes
$path = str_replace('\\', '/', $path);
+
//add leading slash
if ($path[0] !== '/') {
$path = '/' . $path;
}
- //remove duplicate slashes
- while (strpos($path, '//') !== false) {
- $path = str_replace('//', '/', $path);
+
+ // remove '/./'
+ // ugly, but str_replace() can't replace them all in one go
+ // as the replacement itself is part of the search string
+ // which will only be found during the next iteration
+ while (strpos($path, '/./') !== false) {
+ $path = str_replace('/./', '/', $path);
}
+ // remove sequences of slashes
+ $path = preg_replace('#/{2,}#', '/', $path);
+
//remove trailing slash
if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') {
$path = substr($path, 0, -1);
}
+
+ // remove trailing '/.'
+ if (substr($path, -2) == '/.') {
+ $path = substr($path, 0, -2);
+ }
+
//normalize unicode if possible
$path = \OC_Util::normalizeUnicode($path);
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index a5b79f0e967..3943d667c35 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -21,11 +21,11 @@ namespace OC\Files\Storage;
*/
abstract class Common implements \OC\Files\Storage\Storage {
- private $cache;
- private $scanner;
- private $permissioncache;
- private $watcher;
- private $storageCache;
+ protected $cache;
+ protected $scanner;
+ protected $permissioncache;
+ protected $watcher;
+ protected $storageCache;
public function __construct($parameters) {
}
diff --git a/lib/private/files/storage/home.php b/lib/private/files/storage/home.php
index bf1d6017cbf..b4ceb8f4f9b 100644
--- a/lib/private/files/storage/home.php
+++ b/lib/private/files/storage/home.php
@@ -13,6 +13,11 @@ namespace OC\Files\Storage;
*/
class Home extends Local {
/**
+ * @var string
+ */
+ protected $id;
+
+ /**
* @var \OC\User\User $user
*/
protected $user;
@@ -20,11 +25,25 @@ class Home extends Local {
public function __construct($arguments) {
$this->user = $arguments['user'];
$datadir = $this->user->getHome();
+ if (isset($arguments['legacy']) && $arguments['legacy']) {
+ // legacy home id (<= 5.0.12)
+ $this->id = 'local::' . $datadir . '/';
+ }
+ else {
+ $this->id = 'home::' . $this->user->getUID();
+ }
parent::__construct(array('datadir' => $datadir));
}
public function getId() {
- return 'home::' . $this->user->getUID();
+ return $this->id;
+ }
+
+ public function getCache($path = '') {
+ if (!isset($this->cache)) {
+ $this->cache = new \OC\Files\Cache\HomeCache($this);
+ }
+ return $this->cache;
}
}
diff --git a/lib/private/preview/image.php b/lib/private/preview/image.php
index 9aec967282d..84343df2608 100644
--- a/lib/private/preview/image.php
+++ b/lib/private/preview/image.php
@@ -21,11 +21,11 @@ class Image extends Provider {
return false;
}
+ $image = new \OC_Image();
//check if file is encrypted
if($fileInfo['encrypted'] === true) {
- $image = new \OC_Image(stream_get_contents($fileview->fopen($path, 'r')));
+ $image->loadFromData(stream_get_contents($fileview->fopen($path, 'r')));
}else{
- $image = new \OC_Image();
$image->loadFromFile($fileview->getLocalFile($path));
}
diff --git a/lib/private/preview/movies.php b/lib/private/preview/movies.php
index 7e012ec44aa..28f130f7506 100644
--- a/lib/private/preview/movies.php
+++ b/lib/private/preview/movies.php
@@ -69,7 +69,8 @@ if (!\OC_Util::runningOnWindows()) {
unlink($absPath);
if ($returnCode === 0) {
- $image = new \OC_Image($tmpPath);
+ $image = new \OC_Image();
+ $image->loadFromFile($tmpPath);
unlink($tmpPath);
return $image->valid() ? $image : false;
}
diff --git a/lib/private/preview/mp3.php b/lib/private/preview/mp3.php
index 1eed566315c..3fc0ab0490c 100644
--- a/lib/private/preview/mp3.php
+++ b/lib/private/preview/mp3.php
@@ -25,7 +25,8 @@ class MP3 extends Provider {
if(isset($tags['id3v2']['APIC'][0]['data'])) {
$picture = @$tags['id3v2']['APIC'][0]['data'];
unlink($tmpPath);
- $image = new \OC_Image($picture);
+ $image = new \OC_Image();
+ $image->loadFromData($picture);
return $image->valid() ? $image : $this->getNoCoverThumbnail();
}
@@ -39,7 +40,8 @@ class MP3 extends Provider {
return false;
}
- $image = new \OC_Image($icon);
+ $image = new \OC_Image();
+ $image->loadFromFile($icon);
return $image->valid() ? $image : false;
}
diff --git a/lib/private/preview/office-cl.php b/lib/private/preview/office-cl.php
index 8f2e06c050b..b11fed13ba1 100644
--- a/lib/private/preview/office-cl.php
+++ b/lib/private/preview/office-cl.php
@@ -48,7 +48,8 @@ if (!\OC_Util::runningOnWindows()) {
return false;
}
- $image = new \OC_Image($pdf);
+ $image = new \OC_Image();
+ $image->loadFromData($pdf);
unlink($absPath);
unlink($absPath . '.pdf');
diff --git a/lib/private/preview/office-fallback.php b/lib/private/preview/office-fallback.php
index e69ab0ab8cb..f184b3149d5 100644
--- a/lib/private/preview/office-fallback.php
+++ b/lib/private/preview/office-fallback.php
@@ -80,7 +80,8 @@ class MSOfficeExcel extends Provider {
unlink($absPath);
unlink($tmpPath);
- $image = new \OC_Image($pdf);
+ $image = new \OC_Image();
+ $image->loadFromData($pdf);
return $image->valid() ? $image : false;
}
diff --git a/lib/private/setup.php b/lib/private/setup.php
index 9c3034dc06b..b5c530a091f 100644
--- a/lib/private/setup.php
+++ b/lib/private/setup.php
@@ -165,8 +165,19 @@ class OC_Setup {
}
public static function protectDataDirectory() {
- $content = "deny from all\n";
- $content.= "IndexIgnore *";
+ //Require all denied
+ $now = date('Y-m-d H:i:s');
+ $content = "# Generated by ownCloud on $now\n";
+ $content.= "# line below if for Apache 2.4\n";
+ $content.= "<ifModule mod_authz_core>\n";
+ $content.= "Require all denied\n";
+ $content.= "</ifModule>\n\n";
+ $content.= "# line below if for Apache 2.2\n";
+ $content.= "<ifModule !mod_authz_core>\n";
+ $content.= "deny from all\n";
+ $content.= "</ifModule>\n\n";
+ $content.= "# section for Apache 2.2 and 2.4\n";
+ $content.= "IndexIgnore *\n";
file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.htaccess', $content);
file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/index.html', '');
}
diff --git a/lib/public/share.php b/lib/public/share.php
index 01bf61a60a5..caa274b8579 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -354,7 +354,7 @@ class Share {
\OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result) . ', token=' . $token, \OC_Log::ERROR);
}
$row = $result->fetchRow();
- if (self::expireItem($row)) {
+ if (is_array($row) and self::expireItem($row)) {
return false;
}
return $row;