From 5b949596867c986916568e5bea2003e04102aa71 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 22 Feb 2013 14:56:50 +0100 Subject: using the number of writen bytes as indicator if streamCopy() was successfully. Instead check if fwrite returns the number of bytes or false --- lib/files/view.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/files/view.php') diff --git a/lib/files/view.php b/lib/files/view.php index 9ac08c98082..11edbadab9b 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -361,10 +361,9 @@ class View { } else { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); - $count = \OC_Helper::streamCopy($source, $target); + $result = \OC_Helper::streamCopy($source, $target); list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1); $storage1->unlink($internalPath1); - $result = $count > 0; } if ($this->fakeRoot == Filesystem::getRoot()) { \OC_Hook::emit( -- cgit v1.2.3 From d8137fdf66a513d0de4bb234d0427ff27ca40106 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 22 Feb 2013 16:43:11 +0100 Subject: return both, count and result if the operation succeeded or failed. Maybe in some cases it is useful to know how much bytes where copied --- apps/files_sharing/lib/sharedstorage.php | 3 ++- lib/files/storage/common.php | 4 ++-- lib/files/view.php | 8 ++++---- lib/helper.php | 9 ++++++--- lib/public/files.php | 3 ++- 5 files changed, 16 insertions(+), 11 deletions(-) (limited to 'lib/files/view.php') diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 65812b7e2fd..e920329ae49 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -314,7 +314,8 @@ class Shared extends \OC\Files\Storage\Common { if ($this->isCreatable(dirname($path2))) { $source = $this->fopen($path1, 'r'); $target = $this->fopen($path2, 'w'); - return \OC_Helper::streamCopy($source, $target); + list ($count, $result) = \OC_Helper::streamCopy($source, $target); + return $result; } return false; } diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php index 4e7a73e5d4a..fd9ae844a8e 100644 --- a/lib/files/storage/common.php +++ b/lib/files/storage/common.php @@ -97,8 +97,8 @@ abstract class Common implements \OC\Files\Storage\Storage { public function copy($path1, $path2) { $source=$this->fopen($path1, 'r'); $target=$this->fopen($path2, 'w'); - $count=\OC_Helper::streamCopy($source, $target); - return $count>0; + list($count, $result) = \OC_Helper::streamCopy($source, $target); + return $result; } /** diff --git a/lib/files/view.php b/lib/files/view.php index 11edbadab9b..f48d0c8b225 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -285,7 +285,7 @@ class View { } $target = $this->fopen($path, 'w'); if ($target) { - $count = \OC_Helper::streamCopy($data, $target); + list ($count, $result) = \OC_Helper::streamCopy($data, $target); fclose($target); fclose($data); if ($this->fakeRoot == Filesystem::getRoot()) { @@ -303,7 +303,7 @@ class View { ); } \OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count); - return $count > 0; + return $result; } else { return false; } @@ -361,7 +361,7 @@ class View { } else { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); - $result = \OC_Helper::streamCopy($source, $target); + list($count, $result) = \OC_Helper::streamCopy($source, $target); list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1); $storage1->unlink($internalPath1); } @@ -443,7 +443,7 @@ class View { } else { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); - $result = \OC_Helper::streamCopy($source, $target); + list($count, $result) = \OC_Helper::streamCopy($source, $target); } if ($this->fakeRoot == Filesystem::getRoot()) { \OC_Hook::emit( diff --git a/lib/helper.php b/lib/helper.php index 2c9cd36b199..7420a79eb2d 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -513,13 +513,16 @@ class OC_Helper { if(!$source or !$target) { return false; } - $result=true; + $result = true; + $count = 0; while(!feof($source)) { - if (fwrite($target, fread($source, 8192)) === false) { + if ($c = fwrite($target, fread($source, 8192)) === false) { $result = false; + } else { + $count += $c; } } - return $result; + return array($count, $result); } /** diff --git a/lib/public/files.php b/lib/public/files.php index c2945b200e8..700bf574537 100644 --- a/lib/public/files.php +++ b/lib/public/files.php @@ -62,7 +62,8 @@ class Files { * @return int the number of bytes copied */ public static function streamCopy( $source, $target ) { - return(\OC_Helper::streamCopy( $source, $target )); + list($count, $result) = \OC_Helper::streamCopy( $source, $target ); + return $count; } /** -- cgit v1.2.3 From 71bdccf3471ed7ff97c4e636ce18e4a018894d38 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 3 Mar 2013 12:03:26 -0500 Subject: Chunk size comment should say kB, not MB --- lib/files/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/files/view.php') diff --git a/lib/files/view.php b/lib/files/view.php index f48d0c8b225..3e2cb080e1d 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -199,7 +199,7 @@ class View { @ob_end_clean(); $handle = $this->fopen($path, 'rb'); if ($handle) { - $chunkSize = 8192; // 8 MB chunks + $chunkSize = 8192; // 8 kB chunks while (!feof($handle)) { echo fread($handle, $chunkSize); flush(); -- cgit v1.2.3 From 48bb53030c657e1133da47765c7c778a069af665 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Thu, 7 Mar 2013 15:51:44 +0100 Subject: distinguish between touch and write --- apps/files_versions/lib/hooks.php | 6 ++++++ apps/files_versions/lib/versions.php | 1 + lib/files/view.php | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/files/view.php') diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php index 7891b20e92f..6e81286052f 100644 --- a/apps/files_versions/lib/hooks.php +++ b/apps/files_versions/lib/hooks.php @@ -21,6 +21,12 @@ class Hooks { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { $path = $params[\OC\Files\Filesystem::signal_param_path]; + $pos = strrpos($path, '.part'); + if ($pos) { + error_log("old path: $path"); + $path = substr($path, 0, $pos); + error_log("new path: $path"); + } if($path<>'') { Storage::store($path); } diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index c37133cf32c..274f38095db 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -107,6 +107,7 @@ class Storage { // store a new version of a file $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename)); + error_log("version created!"); $versionsSize = self::getVersionsSize($uid); if ( $versionsSize === false || $versionsSize < 0 ) { $versionsSize = self::calculateSize($uid); diff --git a/lib/files/view.php b/lib/files/view.php index 3e2cb080e1d..59339ff2071 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -245,7 +245,14 @@ class View { if (!is_null($mtime) and !is_numeric($mtime)) { $mtime = strtotime($mtime); } - return $this->basicOperation('touch', $path, array('write'), $mtime); + + $hooks = array('touch'); + + if (!$this->file_exists($path)) { + $hooks[] = 'write'; + } + + return $this->basicOperation('touch', $path, $hooks, $mtime); } public function file_get_contents($path) { @@ -596,6 +603,7 @@ class View { if ($path == null) { return false; } + foreach ($hooks as $h) if ($h == "write") error_log("write triggered by $operation for $path"); $run = $this->runHooks($hooks, $path); list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix); if ($run and $storage) { -- cgit v1.2.3 From a5cab28bea6188ce840d7d115064c4780531e13d Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 7 Mar 2013 11:12:59 -0500 Subject: Fix fetching source path of shared files --- apps/files_sharing/lib/share/file.php | 23 ++++++++++++++++++++--- apps/files_sharing/lib/sharedstorage.php | 20 ++++++++++++-------- lib/files/mount.php | 26 ++++++++++++++++++++++++-- lib/files/view.php | 2 +- lib/public/share.php | 2 +- tests/lib/files/mount.php | 8 ++++---- 6 files changed, 62 insertions(+), 19 deletions(-) (limited to 'lib/files/view.php') diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php index 0aeb763d89a..fa43e87b49e 100644 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@ -73,7 +73,9 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { if ($format == self::FORMAT_SHARED_STORAGE) { // Only 1 item should come through for this format call return array( + 'parent' => $items[key($items)]['parent'], 'path' => $items[key($items)]['path'], + 'storage' => $items[key($items)]['storage'], 'permissions' => $items[key($items)]['permissions'], 'uid_owner' => $items[key($items)]['uid_owner'] ); @@ -139,13 +141,28 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { $source = \OCP\Share::getItemSharedWith('folder', $folder, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE); if ($source) { $source['path'] = $source['path'].substr($target, strlen($folder)); - return $source; } } else { $source = \OCP\Share::getItemSharedWith('file', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE); - if ($source) { - return $source; + } + if ($source) { + if (isset($source['parent'])) { + $parent = $source['parent']; + while (isset($parent)) { + $query = \OC_DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1); + $item = $query->execute(array($parent))->fetchRow(); + if (isset($item['parent'])) { + $parent = $item['parent']; + } else { + $fileOwner = $item['uid_owner']; + break; + } + } + } else { + $fileOwner = $source['uid_owner']; } + $source['fileOwner'] = $fileOwner; + return $source; } \OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::ERROR); return false; diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 5a9864b64ba..be0e59e6732 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -45,11 +45,7 @@ class Shared extends \OC\Files\Storage\Common { */ private function getFile($target) { if (!isset($this->files[$target])) { - $source = \OC_Share_Backend_File::getSource($target); - if ($source) { - $source['path'] = '/'.$source['uid_owner'].'/'.$source['path']; - } - $this->files[$target] = $source; + $this->files[$target] = \OC_Share_Backend_File::getSource($target); } return $this->files[$target]; } @@ -62,8 +58,16 @@ class Shared extends \OC\Files\Storage\Common { private function getSourcePath($target) { $source = $this->getFile($target); if ($source) { - \OC\Files\Filesystem::initMountPoints($source['uid_owner']); - return $source['path']; + if (!isset($source['fullPath'])) { + \OC\Files\Filesystem::initMountPoints($source['fileOwner']); + $mount = \OC\Files\Mount::findByNumericId($source['storage']); + if ($mount) { + $this->files[$target]['fullPath'] = $mount->getMountPoint().$source['path']; + } else { + $this->files[$target]['fullPath'] = false; + } + } + return $this->files[$target]['fullPath']; } return false; } @@ -430,7 +434,7 @@ class Shared extends \OC\Files\Storage\Common { } $source = $this->getFile($path); if ($source) { - return $source['uid_owner']; + return $source['fileOwner']; } return false; } diff --git a/lib/files/mount.php b/lib/files/mount.php index 6e99d8eabb4..1c9382d78e7 100644 --- a/lib/files/mount.php +++ b/lib/files/mount.php @@ -176,10 +176,12 @@ class Mount { } /** + * Find mounts by storage id + * * @param string $id - * @return \OC\Files\Storage\Storage[] + * @return Mount[] */ - public static function findById($id) { + public static function findByStorageId($id) { if (strlen($id) > 64) { $id = md5($id); } @@ -191,4 +193,24 @@ class Mount { } return $result; } + + /** + * Find mounts by numeric storage id + * + * @param string $id + * @return Mount + */ + public static function findByNumericId($id) { + $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?'); + $result = $query->execute(array($id))->fetchOne(); + if ($result) { + $id = $result; + foreach (self::$mounts as $mount) { + if ($mount->getStorageId() === $id) { + return $mount; + } + } + } + return false; + } } diff --git a/lib/files/view.php b/lib/files/view.php index 3e2cb080e1d..4ed3234552e 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -960,7 +960,7 @@ class View { */ public function getPath($id) { list($storage, $internalPath) = Cache\Cache::getById($id); - $mounts = Mount::findById($storage); + $mounts = Mount::findByStorageId($storage); foreach ($mounts as $mount) { /** * @var \OC\Files\Mount $mount diff --git a/lib/public/share.php b/lib/public/share.php index 8146a23f360..59f41a9bfd6 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -786,7 +786,7 @@ class Share { } else { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, - `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`'; + `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`'; } } else { $select = '*'; diff --git a/tests/lib/files/mount.php b/tests/lib/files/mount.php index 4e6aaf0679b..6a5c025b0e1 100644 --- a/tests/lib/files/mount.php +++ b/tests/lib/files/mount.php @@ -42,7 +42,7 @@ class Mount extends \PHPUnit_Framework_TestCase { $this->assertEquals(array($mount), \OC\Files\Mount::findById($id)); $mount2 = new \OC\Files\Mount($storage, '/foo/bar'); - $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findById($id)); + $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findByStorageId($id)); } public function testLong() { @@ -51,8 +51,8 @@ class Mount extends \PHPUnit_Framework_TestCase { $id = $mount->getStorageId(); $storageId = $storage->getId(); - $this->assertEquals(array($mount), \OC\Files\Mount::findById($id)); - $this->assertEquals(array($mount), \OC\Files\Mount::findById($storageId)); - $this->assertEquals(array($mount), \OC\Files\Mount::findById(md5($storageId))); + $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($id)); + $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($storageId)); + $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId(md5($storageId))); } } -- cgit v1.2.3 From 8d26400cb5427763b0562da8799bea52f4eae21e Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Fri, 8 Mar 2013 11:27:25 +0100 Subject: remove some debug output; move code to the right function --- apps/files_versions/lib/hooks.php | 6 ------ apps/files_versions/lib/versions.php | 8 ++++++++ lib/files/view.php | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/files/view.php') diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php index 6e81286052f..7891b20e92f 100644 --- a/apps/files_versions/lib/hooks.php +++ b/apps/files_versions/lib/hooks.php @@ -21,12 +21,6 @@ class Hooks { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { $path = $params[\OC\Files\Filesystem::signal_param_path]; - $pos = strrpos($path, '.part'); - if ($pos) { - error_log("old path: $path"); - $path = substr($path, 0, $pos); - error_log("new path: $path"); - } if($path<>'') { Storage::store($path); } diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 79b16f2586f..20611c61ec7 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -82,6 +82,14 @@ class Storage { */ public static function store($filename) { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { + + // if the file gets streamed we need to remove the .part extension + // to get the right target + $ext = pathinfo($filename, PATHINFO_EXTENSION); + if ($ext === 'part') { + $filename = substr($filename, 0, strlen($filename)-5); + } + list($uid, $filename) = self::getUidAndFilename($filename); $files_view = new \OC\Files\View('/'.$uid .'/files'); diff --git a/lib/files/view.php b/lib/files/view.php index 59339ff2071..fe753342b6c 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -603,7 +603,7 @@ class View { if ($path == null) { return false; } - foreach ($hooks as $h) if ($h == "write") error_log("write triggered by $operation for $path"); + $run = $this->runHooks($hooks, $path); list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix); if ($run and $storage) { -- cgit v1.2.3