diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/api.php | 21 | ||||
-rw-r--r-- | lib/private/connector/sabre/file.php | 28 | ||||
-rw-r--r-- | lib/private/files/cache/homecache.php | 40 | ||||
-rw-r--r-- | lib/private/files/filesystem.php | 14 | ||||
-rw-r--r-- | lib/private/files/storage/common.php | 10 | ||||
-rw-r--r-- | lib/private/files/storage/home.php | 21 |
6 files changed, 113 insertions, 21 deletions
diff --git a/lib/private/api.php b/lib/private/api.php index 8307f209d21..45e7f18bd4e 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,17 +143,17 @@ 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; } } } @@ -177,10 +180,10 @@ class OC_API { $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->getStatusCode(); } 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/filesystem.php b/lib/private/files/filesystem.php index e40502bbe64..899666f3e1a 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"); 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; } } |