diff options
author | tomneedham <tom@owncloud.com> | 2013-11-14 00:40:57 +0000 |
---|---|---|
committer | tomneedham <tom@owncloud.com> | 2013-11-14 00:40:57 +0000 |
commit | 00944a376a83695256f91f800bece1d2de10b89e (patch) | |
tree | 3b892dfb8ff75361fd15eaf5b6eef479e13d6088 /lib | |
parent | 959513fdc866910855b886051394962ab0ee582e (diff) | |
parent | 8d0d0836bae968d3abff5f5ff9db230d449397a6 (diff) | |
download | nextcloud-server-00944a376a83695256f91f800bece1d2de10b89e.tar.gz nextcloud-server-00944a376a83695256f91f800bece1d2de10b89e.zip |
Merge branch 'master' into oc_api_tests
Diffstat (limited to 'lib')
-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 |
5 files changed, 101 insertions, 12 deletions
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; } } |