diff options
Diffstat (limited to 'apps/files_versions/lib')
-rw-r--r-- | apps/files_versions/lib/capabilities.php | 2 | ||||
-rw-r--r-- | apps/files_versions/lib/hooks.php | 15 | ||||
-rw-r--r-- | apps/files_versions/lib/versions.php | 49 |
3 files changed, 39 insertions, 27 deletions
diff --git a/apps/files_versions/lib/capabilities.php b/apps/files_versions/lib/capabilities.php index 3251a07b6ae..45d7dd3fb02 100644 --- a/apps/files_versions/lib/capabilities.php +++ b/apps/files_versions/lib/capabilities.php @@ -20,4 +20,4 @@ class Capabilities { )); } -}
\ No newline at end of file +} diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php index f0082b301a3..81ee3c8b3c6 100644 --- a/apps/files_versions/lib/hooks.php +++ b/apps/files_versions/lib/hooks.php @@ -19,7 +19,7 @@ class Hooks { */ public static function write_hook( $params ) { - if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { + if (\OCP\App::isEnabled('files_versions')) { $path = $params[\OC\Files\Filesystem::signal_param_path]; if($path<>'') { Storage::store($path); @@ -36,12 +36,12 @@ class Hooks { * cleanup the versions directory if the actual file gets deleted */ public static function remove_hook($params) { - if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { + + if (\OCP\App::isEnabled('files_versions')) { $path = $params[\OC\Files\Filesystem::signal_param_path]; if($path<>'') { Storage::delete($path); } - } } @@ -53,13 +53,13 @@ class Hooks { * of the stored versions along the actual file */ public static function rename_hook($params) { - if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { + + if (\OCP\App::isEnabled('files_versions')) { $oldpath = $params['oldpath']; $newpath = $params['newpath']; if($oldpath<>'' && $newpath<>'') { Storage::rename( $oldpath, $newpath ); } - } } @@ -71,10 +71,11 @@ class Hooks { * to remove the used space for versions stored in the database */ public static function deleteUser_hook($params) { - if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { + + if (\OCP\App::isEnabled('files_versions')) { $uid = $params['uid']; Storage::deleteUser($uid); - } + } } } diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 70b8f30be5c..0b4699dc5c0 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'); @@ -104,17 +104,12 @@ class Storage { // we should have a source file to work with, and the file shouldn't // be empty $fileExists = $files_view->file_exists($filename); - $fileSize = $files_view->filesize($filename); - if ($fileExists === false || $fileSize === 0) { + if (!($fileExists && $files_view->filesize($filename) > 0)) { return false; } // create all parent folders - $info=pathinfo($filename); - $versionsFolderName=$versions_view->getLocalFolder(''); - if(!file_exists($versionsFolderName.'/'.$info['dirname'])) { - mkdir($versionsFolderName.'/'.$info['dirname'], 0750, true); - } + self::createMissingDirectories($filename, $users_view); $versionsSize = self::getVersionsSize($uid); if ( $versionsSize === false || $versionsSize < 0 ) { @@ -174,7 +169,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)) { @@ -183,13 +178,12 @@ 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 + self::createMissingDirectories($newpath, new \OC\Files\View('/'. $uidn)); + foreach ($versions as $v) { $versions_view->rename($oldpath.'.v'.$v['version'], $newpath.'.v'.$v['version']); } @@ -435,7 +429,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); @@ -568,4 +562,21 @@ class Storage { return $size; } + /** + * @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(dirname($filename)); + $dirParts = explode('/', $dirname); + $dir = "/files_versions"; + foreach ($dirParts as $part) { + $dir = $dir . '/' . $part; + if (!$view->file_exists($dir)) { + $view->mkdir($dir); + } + } + } + } |