From 0fb719dffe5c2240c97da6ecb37b4437b7ba0391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 16 Sep 2013 10:43:53 +0200 Subject: [PATCH 01/11] adding size() to the file cache --- lib/cache/file.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/cache/file.php b/lib/cache/file.php index 361138e4736..eed2637c981 100644 --- a/lib/cache/file.php +++ b/lib/cache/file.php @@ -40,6 +40,24 @@ class OC_Cache_File{ return $result; } + /** + * Returns the size of the stored/cached data + * + * @param $key + * @return int + */ + public function size($key) { + $result = 0; + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + if ($this->hasKey($key)) { + $storage = $this->getStorage(); + $result = $storage->filesize($key); + } + \OC_FileProxy::$enabled = $proxyStatus; + return $result; + } + public function set($key, $value, $ttl=0) { $storage = $this->getStorage(); $result = false; From 16ef5a8b357e623b1f1621c3e52957167e93e46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 16 Sep 2013 10:47:29 +0200 Subject: [PATCH 02/11] returning the number of stored bytes in store() and adding cleanup() method --- lib/filechunking.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/filechunking.php b/lib/filechunking.php index e6d69273a44..c0e3acbf1aa 100644 --- a/lib/filechunking.php +++ b/lib/filechunking.php @@ -34,10 +34,19 @@ class OC_FileChunking { return $this->cache; } + /** + * Stores the given $data under the given $key - the number of stored bytes is returned + * + * @param $index + * @param $data + * @return int + */ public function store($index, $data) { $cache = $this->getCache(); $name = $this->getPrefix().$index; $cache->set($name, $data); + + return $cache->size($name); } public function isComplete() { @@ -58,12 +67,24 @@ class OC_FileChunking { $count = 0; for($i=0; $i < $this->info['chunkcount']; $i++) { $chunk = $cache->get($prefix.$i); - $cache->remove($prefix.$i); $count += fwrite($f, $chunk); } + + $this->cleanup(); return $count; } + /** + * Removes all chunks which belong to this transmission + */ + public function cleanup() { + $cache = $this->getCache(); + $prefix = $this->getPrefix(); + for($i=0; $i < $this->info['chunkcount']; $i++) { + $cache->remove($prefix.$i); + } + } + public function signature_split($orgfile, $input) { $info = unpack('n', fread($input, 2)); $blocksize = $info[1]; From 39599019e5c3e47c5d03a1b63b438cacdab5b37e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 16 Sep 2013 10:48:21 +0200 Subject: [PATCH 03/11] adding detection of aborted uploads --- lib/connector/sabre/directory.php | 99 ++++++++++++++++++------------- 1 file changed, 58 insertions(+), 41 deletions(-) diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index 3181a4b310f..8a092c2455a 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -55,53 +55,40 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa } if (isset($_SERVER['HTTP_OC_CHUNKED'])) { - $info = OC_FileChunking::decodeName($name); - if (empty($info)) { - throw new Sabre_DAV_Exception_NotImplemented(); - } - $chunk_handler = new OC_FileChunking($info); - $chunk_handler->store($info['index'], $data); - if ($chunk_handler->isComplete()) { - $newPath = $this->path . '/' . $info['name']; - $chunk_handler->file_assemble($newPath); - return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); - } - } else { - $newPath = $this->path . '/' . $name; + return $this->createFileChunked($name, $data); + } + $newPath = $this->path . '/' . $name; - // mark file as partial while uploading (ignored by the scanner) - $partpath = $newPath . '.part'; + // mark file as partial while uploading (ignored by the scanner) + $partpath = $newPath . '.part'; - \OC\Files\Filesystem::file_put_contents($partpath, $data); + \OC\Files\Filesystem::file_put_contents($partpath, $data); - //detect aborted upload - if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) { - if (isset($_SERVER['CONTENT_LENGTH'])) { - $expected = $_SERVER['CONTENT_LENGTH']; - $actual = \OC\Files\Filesystem::filesize($partpath); - if ($actual != $expected) { - \OC\Files\Filesystem::unlink($partpath); - throw new Sabre_DAV_Exception_BadRequest( - 'expected filesize ' . $expected . ' got ' . $actual); - } + //detect aborted upload + if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) { + if (isset($_SERVER['CONTENT_LENGTH'])) { + $expected = $_SERVER['CONTENT_LENGTH']; + $actual = \OC\Files\Filesystem::filesize($partpath); + if ($actual != $expected) { + \OC\Files\Filesystem::unlink($partpath); + throw new Sabre_DAV_Exception_BadRequest( + 'expected filesize ' . $expected . ' got ' . $actual); } } - - // rename to correct path - \OC\Files\Filesystem::rename($partpath, $newPath); - - // allow sync clients to send the mtime along in a header - $mtime = OC_Request::hasModificationTime(); - if ($mtime !== false) { - if(\OC\Files\Filesystem::touch($newPath, $mtime)) { - header('X-OC-MTime: accepted'); - } - } - - return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); } - return null; + // rename to correct path + \OC\Files\Filesystem::rename($partpath, $newPath); + + // allow sync clients to send the mtime along in a header + $mtime = OC_Request::hasModificationTime(); + if ($mtime !== false) { + if(\OC\Files\Filesystem::touch($newPath, $mtime)) { + header('X-OC-MTime: accepted'); + } + } + + return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); } /** @@ -250,7 +237,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa * If the array is empty, all properties should be returned * * @param array $properties - * @return void + * @return array */ public function getProperties($properties) { $props = parent::getProperties($properties); @@ -260,4 +247,34 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa } return $props; } + + private function createFileChunked($name, $data) + { + $info = OC_FileChunking::decodeName($name); + if (empty($info)) { + throw new Sabre_DAV_Exception_NotImplemented(); + } + $chunk_handler = new OC_FileChunking($info); + $bytesWritten = $chunk_handler->store($info['index'], $data); + + //detect aborted upload + if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) { + if (isset($_SERVER['CONTENT_LENGTH'])) { + $expected = $_SERVER['CONTENT_LENGTH']; + if ($bytesWritten != $expected) { + $chunk_handler->cleanup(); + throw new Sabre_DAV_Exception_BadRequest( + 'expected filesize ' . $expected . ' got ' . $bytesWritten); + } + } + } + + if ($chunk_handler->isComplete()) { + $newPath = $this->path . '/' . $info['name']; + $chunk_handler->file_assemble($newPath); + return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); + } + + return null; + } } From 61a534fb60eb275344e6cf7890fdfe88657e53a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 7 Oct 2013 17:49:21 +0200 Subject: [PATCH 04/11] moving createFileChunked() to OC_Connector_Sabre_File --- lib/private/connector/sabre/file.php | 49 +++++++++++++++++++--------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 8ffec371e3f..f2191732c0d 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -58,21 +58,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D // chunked handling if (isset($_SERVER['HTTP_OC_CHUNKED'])) { - list(, $name) = \Sabre_DAV_URLUtil::splitPath($this->path); - - $info = OC_FileChunking::decodeName($name); - if (empty($info)) { - throw new Sabre_DAV_Exception_NotImplemented(); - } - $chunk_handler = new OC_FileChunking($info); - $chunk_handler->store($info['index'], $data); - if ($chunk_handler->isComplete()) { - $newPath = $this->path . '/' . $info['name']; - $chunk_handler->file_assemble($newPath); - return $this->getETagPropertyForPath($newPath); - } - - return null; + return $this->createFileChunked($data); } // mark file as partial while uploading (ignored by the scanner) @@ -189,4 +175,37 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D return \OC\Files\Filesystem::getMimeType($this->path); } + + private function createFileChunked($data) + { + list($path, $name) = \Sabre_DAV_URLUtil::splitPath($this->path); + + $info = OC_FileChunking::decodeName($name); + if (empty($info)) { + throw new Sabre_DAV_Exception_NotImplemented(); + } + $chunk_handler = new OC_FileChunking($info); + $bytesWritten = $chunk_handler->store($info['index'], $data); + + //detect aborted upload + if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) { + if (isset($_SERVER['CONTENT_LENGTH'])) { + $expected = $_SERVER['CONTENT_LENGTH']; + if ($bytesWritten != $expected) { + $chunk_handler->cleanup(); + throw new Sabre_DAV_Exception_BadRequest( + 'expected filesize ' . $expected . ' got ' . $bytesWritten); + } + } + } + + if ($chunk_handler->isComplete()) { + $newPath = $path . '/' . $info['name']; + $chunk_handler->file_assemble($newPath); + return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); + } + + return null; + } + } From 3dd313dca2ce1aa94510aa8639d5aa8ad6db3185 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 10 Oct 2013 19:46:45 +0200 Subject: [PATCH 05/11] add "received_from" and "received_from_displayname" field in case of a reshared file to the output --- apps/files_sharing/lib/api.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/files_sharing/lib/api.php b/apps/files_sharing/lib/api.php index e6624624898..bd9beddf063 100644 --- a/apps/files_sharing/lib/api.php +++ b/apps/files_sharing/lib/api.php @@ -31,11 +31,11 @@ class Api { * @return \OC_OCS_Result share information */ public static function getAllShares($params) { - // if a file is specified, get the share for this file if (isset($_GET['path'])) { $params['itemSource'] = self::getFileId($_GET['path']); $params['path'] = $_GET['path']; + $params['itemType'] = self::getItemType($_GET['path']); if (isset($_GET['subfiles']) && $_GET['subfiles'] === 'true') { return self::getSharesFromFolder($params); } @@ -59,20 +59,22 @@ class Api { * @return \OC_OCS_Result share information */ public static function getShare($params) { - // either the $params already contains a itemSource if we come from // getAllShare() or we need to translate the shareID to a itemSource if(isset($params['itemSource'])) { $itemSource = $params['itemSource']; + $itemType = $params['itemType']; $getSpecificShare = true; } else { $s = self::getShareFromId($params['id']); $itemSource = $s['item_source']; + $itemType = $s['item_type']; $getSpecificShare = false; } if ($itemSource !== null) { - $shares = \OCP\Share::getItemShared('file', $itemSource); + $shares = \OCP\Share::getItemShared($itemType, $itemSource); + $reshare = \OCP\Share::getItemSharedWithBySource($itemType, $itemSource); // if a specific share was specified only return this one if ($getSpecificShare === false) { foreach ($shares as $share) { @@ -82,6 +84,10 @@ class Api { } } } + if ($reshare) { + $shares['received_from'] = $reshare['uid_owner']; + $shares['received_from_displayname'] = \OCP\User::getDisplayName($reshare['uid_owner']); + } } else { $shares = null; } @@ -110,7 +116,14 @@ class Api { $result = array(); foreach ($content as $file) { - $share = \OCP\Share::getItemShared('file', $file['fileid']); + // workaround because folders are named 'dir' in this context + $itemType = $file['type'] === 'file' ? 'file' : 'folder'; + $share = \OCP\Share::getItemShared($itemType, $file['fileid']); + $reshare = \OCP\Share::getItemSharedWithBySource($itemType, $file['fileid']); + if ($reshare) { + $share['received_from'] = $reshare['uid_owner']; + $share['received_from_displayname'] = \OCP\User::getDisplayName($reshare['uid_owner']); + } if ($share) { $share['filename'] = $file['name']; $result[] = $share; @@ -132,7 +145,6 @@ class Api { if($path === null) { return new \OC_OCS_Result(null, 400, "please specify a file or folder path"); } - $itemSource = self::getFileId($path); $itemType = self::getItemType($path); @@ -184,7 +196,7 @@ class Api { if ($token) { $data = array(); $data['id'] = 'unknown'; - $shares = \OCP\Share::getItemShared('file', $itemSource); + $shares = \OCP\Share::getItemShared($itemType, $itemSource); if(is_string($token)) { //public link share foreach ($shares as $share) { if ($share['token'] === $token) { @@ -414,7 +426,6 @@ class Api { $view = new \OC\Files\View('/'.\OCP\User::getUser().'/files'); $fileId = null; - $fileInfo = $view->getFileInfo($path); if ($fileInfo) { $fileId = $fileInfo['fileid']; From 7a1705d28eff8bfcf5921fe8dc181a05f6a5f5a7 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 11 Oct 2013 10:28:01 +0200 Subject: [PATCH 06/11] fix api tests --- apps/files_sharing/tests/api.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php index 63df0dd7dc3..32795d9d557 100644 --- a/apps/files_sharing/tests/api.php +++ b/apps/files_sharing/tests/api.php @@ -196,7 +196,8 @@ class Test_Files_Sharing_Api extends \PHPUnit_Framework_TestCase { \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null, 1); - $params = array('itemSource' => $fileInfo['fileid']); + $params = array('itemSource' => $fileInfo['fileid'], + 'itemType' => 'file'); $result = Share\Api::getShare($params); From b8285ca316851377dd58cc69cf797ed4eb6b2e41 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 14 Oct 2013 12:12:26 +0200 Subject: [PATCH 07/11] Added missing "grid" class on external storage's table --- apps/files_external/templates/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index 028a384cf34..0d318a183c7 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -2,7 +2,7 @@

t('External Storage')); ?>

'')) print_unescaped(''.$_['dependencies'].''); ?> - '> +
'> From e79d85386768b30ed795c1e119e158b5acac5307 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 14 Oct 2013 17:05:24 +0200 Subject: [PATCH 08/11] Removed extra bkg color on file actions when row is selected/hovered on --- apps/files/css/files.css | 8 -------- 1 file changed, 8 deletions(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index c4a231551b1..ac2a243f2b4 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -239,14 +239,6 @@ table td.filename form { font-size:.85em; margin-left:3em; margin-right:3em; } top: 14px; right: 0; } -#fileList tr:hover .fileactions { /* background to distinguish when overlaying with file names */ - background-color: rgba(240,240,240,0.898); - box-shadow: -5px 0 7px rgba(240,240,240,0.898); -} -#fileList tr.selected:hover .fileactions, #fileList tr.mouseOver .fileactions { /* slightly darker color for selected rows */ - background-color: rgba(230,230,230,.9); - box-shadow: -5px 0 7px rgba(230,230,230,.9); -} #fileList img.move2trash { display:inline; margin:-.5em 0; padding:1em .5em 1em .5em !important; float:right; } #fileList a.action.delete { From d3af7a9aa47c99116badc3ab2546d04abc1edf6e Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 14 Oct 2013 17:13:14 +0200 Subject: [PATCH 09/11] check if we are writing to user/files, otherwise skip encryption --- apps/files_encryption/lib/proxy.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 8621c1ba51d..04795b35670 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -47,7 +47,8 @@ class Proxy extends \OC_FileProxy { */ private static function shouldEncrypt($path) { - if (\OCP\App::isEnabled('files_encryption') === false || Crypt::mode() !== 'server') { + if (\OCP\App::isEnabled('files_encryption') === false || Crypt::mode() !== 'server' || + strpos($path, '/' . \OCP\User::getUser() . '/files') !== 0) { return false; } From 6df5c7ebd533f0c499197c83e04c4edc786db192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 14 Oct 2013 21:33:23 +0200 Subject: [PATCH 10/11] streamCopy() should return proper structure. Callers of streamCopy() expect an array to be returned containing count and result. --- lib/private/helper.php | 4 ++-- tests/lib/helper.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/private/helper.php b/lib/private/helper.php index a34640d8e36..1236e748256 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -509,11 +509,11 @@ class OC_Helper { * * @param resource $source * @param resource $target - * @return int the number of bytes copied + * @return array the number of bytes copied and result */ public static function streamCopy($source, $target) { if (!$source or !$target) { - return false; + return array(0, false); } $result = true; $count = 0; diff --git a/tests/lib/helper.php b/tests/lib/helper.php index b4d896e5196..babafab52c0 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -208,4 +208,38 @@ class Test_Helper extends PHPUnit_Framework_TestCase { ->will($this->returnValue(true)); // filename(1) (2) (3).ext exists $this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock)); } + + /** + * @dataProvider streamCopyDataProvider + */ + public function testStreamCopy($expectedCount, $expectedResult, $source, $target) { + + if (is_string($source)) { + $source = fopen($source, 'r'); + } + if (is_string($target)) { + $target = fopen($target, 'w'); + } + + list($count, $result) = \OC_Helper::streamCopy($source, $target); + + if (is_resource($source)) { + fclose($source); + } + if (is_resource($target)) { + fclose($target); + } + + $this->assertSame($expectedCount, $count); + $this->assertSame($expectedResult, $result); + } + + + function streamCopyDataProvider() { + return array( + array(0, false, false, false), + array(0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false), + array(446, true, \OC::$SERVERROOT . '/tests/data/lorem.txt', \OC::$SERVERROOT . '/tests/data/lorem-copy.txt'), + ); + } } From 06f9b7b8628ca81eccca70395cf8475748ab2d8b Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 14 Oct 2013 22:30:38 +0200 Subject: [PATCH 11/11] Fix logout link HTML. --- lib/private/user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/user.php b/lib/private/user.php index b68786c773c..6b350d4cf1b 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -325,7 +325,7 @@ class OC_User { return $backend->getLogoutAttribute(); } - return "href=" . link_to('', 'index.php') . "?logout=true"; + return 'href="' . link_to('', 'index.php') . '?logout=true"'; } /**