From d314729ceaf26a373af8a43ca74e20393e6159dc Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 14 Aug 2013 17:58:41 +0200 Subject: use OC files API to create missing directory which should handle special chars in every environment correctly --- apps/files_versions/lib/versions.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'apps/files_versions/lib') diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 70b8f30be5c..b0fde6b559f 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -110,10 +110,13 @@ class Storage { } // create all parent folders - $info=pathinfo($filename); - $versionsFolderName=$versions_view->getLocalFolder(''); - if(!file_exists($versionsFolderName.'/'.$info['dirname'])) { - mkdir($versionsFolderName.'/'.$info['dirname'], 0750, true); + $dirname= \OC_Filesystem::normalizePath(pathinfo($filename, PATHINFO_DIRNAME)); + $dirParts = explode('/', $dirname); + foreach ($dirParts as $part) { + $dir = $dir.'/'.$part; + if(!$versions_view->file_exists($dir)) { + $versions_view->mkdir($dir); + } } $versionsSize = self::getVersionsSize($uid); -- cgit v1.2.3 From a3d009e3b58099dfd86c53329290665ed09f7d72 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 14 Aug 2013 20:51:36 +0200 Subject: also create root dir if it doesn't exist yet --- apps/files_versions/lib/versions.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'apps/files_versions/lib') diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index b0fde6b559f..ddf73f415c5 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -112,10 +112,11 @@ class Storage { // create all parent folders $dirname= \OC_Filesystem::normalizePath(pathinfo($filename, PATHINFO_DIRNAME)); $dirParts = explode('/', $dirname); + $dir = "/files_versions"; foreach ($dirParts as $part) { $dir = $dir.'/'.$part; - if(!$versions_view->file_exists($dir)) { - $versions_view->mkdir($dir); + if(!$users_view->file_exists($dir)) { + $users_view->mkdir($dir); } } @@ -186,13 +187,19 @@ class Storage { self::expire($newpath); - $abs_newpath = $versions_view->getLocalFile($newpath); - if ( $files_view->is_dir($oldpath) && $versions_view->is_dir($oldpath) ) { $versions_view->rename($oldpath, $newpath); } else if ( ($versions = Storage::getVersions($uid, $oldpath)) ) { - $info=pathinfo($abs_newpath); - if(!file_exists($info['dirname'])) mkdir($info['dirname'], 0750, true); + // create missing dirs if necessary + $dirname = \OC_Filesystem::normalizePath(pathinfo($newpath, PATHINFO_DIRNAME)); + $dirParts = explode('/', $dirname); + $dir = "/files_versions"; + foreach ($dirParts as $part) { + $dir = $dir.'/'.$part; + if(!$users_view->file_exists($dir)) { + $users_view->mkdir($dir); + } + } foreach ($versions as $v) { $versions_view->rename($oldpath.'.v'.$v['version'], $newpath.'.v'.$v['version']); } -- cgit v1.2.3 From f71794f0d5a09686e2bcf1a5b6ec0b19076a43e5 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Sat, 17 Aug 2013 13:28:35 +0200 Subject: added createMissingDirectories() method --- apps/files_versions/lib/versions.php | 53 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'apps/files_versions/lib') diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index ddf73f415c5..39220f43d5f 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -48,14 +48,14 @@ class Storage { /** * get current size of all versions from a given user - * + * * @param $user user who owns the versions * @return mixed versions size or false if no versions size is stored */ private static function getVersionsSize($user) { $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*files_versions` WHERE `user`=?'); $result = $query->execute(array($user))->fetchAll(); - + if ($result) { return $result[0]['size']; } @@ -64,7 +64,7 @@ class Storage { /** * write to the database how much space is in use for versions - * + * * @param $user owner of the versions * @param $size size of the versions */ @@ -76,20 +76,20 @@ class Storage { } $query->execute(array($size, $user)); } - + /** * store a new version of a file. */ 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'); @@ -110,15 +110,7 @@ class Storage { } // create all parent folders - $dirname= \OC_Filesystem::normalizePath(pathinfo($filename, PATHINFO_DIRNAME)); - $dirParts = explode('/', $dirname); - $dir = "/files_versions"; - foreach ($dirParts as $part) { - $dir = $dir.'/'.$part; - if(!$users_view->file_exists($dir)) { - $users_view->mkdir($dir); - } - } + self::createMissingDirectories($filename, $users_view); $versionsSize = self::getVersionsSize($uid); if ( $versionsSize === false || $versionsSize < 0 ) { @@ -178,7 +170,7 @@ class Storage { list($uidn, $newpath) = self::getUidAndFilename($new_path); $versions_view = new \OC\Files\View('/'.$uid .'/files_versions'); $files_view = new \OC\Files\View('/'.$uid .'/files'); - + // if the file already exists than it was a upload of a existing file // over the web interface -> store() is the right function we need here if ($files_view->file_exists($newpath)) { @@ -191,15 +183,8 @@ class Storage { $versions_view->rename($oldpath, $newpath); } else if ( ($versions = Storage::getVersions($uid, $oldpath)) ) { // create missing dirs if necessary - $dirname = \OC_Filesystem::normalizePath(pathinfo($newpath, PATHINFO_DIRNAME)); - $dirParts = explode('/', $dirname); - $dir = "/files_versions"; - foreach ($dirParts as $part) { - $dir = $dir.'/'.$part; - if(!$users_view->file_exists($dir)) { - $users_view->mkdir($dir); - } - } + self::createMissingDirectories($newpath, new \OC\Files\View('/'. $uidn)); + foreach ($versions as $v) { $versions_view->rename($oldpath.'.v'.$v['version'], $newpath.'.v'.$v['version']); } @@ -445,7 +430,7 @@ class Storage { } else { $quota = \OCP\Util::computerFileSize($quota); } - + // make sure that we have the current size of the version history if ( $versionsSize === null ) { $versionsSize = self::getVersionsSize($uid); @@ -578,4 +563,20 @@ class Storage { return $size; } + /** + * @brief create recursively missing directories + * @param string $filename $path to a file + */ + private static function createMissingDirectories($filename, $view) { + $dirname = \OC_Filesystem::normalizePath(pathinfo($filename, PATHINFO_DIRNAME)); + $dirParts = explode('/', $dirname); + $dir = "/files_versions"; + foreach ($dirParts as $part) { + $dir = $dir . '/' . $part; + if (!$view->file_exists($dir)) { + $view->mkdir($dir); + } + } + } + } -- cgit v1.2.3 From db8fdd5032ca3c4b4fa54cc617909abf3525622c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Sat, 17 Aug 2013 13:46:33 +0200 Subject: added missing parameter documentation --- apps/files_versions/lib/versions.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'apps/files_versions/lib') diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 39220f43d5f..d91654fe24a 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -184,7 +184,7 @@ class Storage { } else if ( ($versions = Storage::getVersions($uid, $oldpath)) ) { // create missing dirs if necessary self::createMissingDirectories($newpath, new \OC\Files\View('/'. $uidn)); - + foreach ($versions as $v) { $versions_view->rename($oldpath.'.v'.$v['version'], $newpath.'.v'.$v['version']); } @@ -566,6 +566,7 @@ class Storage { /** * @brief create recursively missing directories * @param string $filename $path to a file + * @param \OC\Files\View $view view on data/user/ */ private static function createMissingDirectories($filename, $view) { $dirname = \OC_Filesystem::normalizePath(pathinfo($filename, PATHINFO_DIRNAME)); -- cgit v1.2.3 From f28f528431fceca7daa3b27edcd1f564ad152086 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Sat, 17 Aug 2013 13:49:42 +0200 Subject: switched to dirname() --- apps/files_versions/lib/versions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_versions/lib') diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index d91654fe24a..f8537f10c4a 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -569,7 +569,7 @@ class Storage { * @param \OC\Files\View $view view on data/user/ */ private static function createMissingDirectories($filename, $view) { - $dirname = \OC_Filesystem::normalizePath(pathinfo($filename, PATHINFO_DIRNAME)); + $dirname = \OC_Filesystem::normalizePath(dirname($filename)); $dirParts = explode('/', $dirname); $dir = "/files_versions"; foreach ($dirParts as $part) { -- cgit v1.2.3