Fixes to code formatting and indentation

This commit is contained in:
Sam Tuke 2013-05-09 18:24:07 +02:00
parent 92e28839ff
commit 163fe64016
1 changed files with 99 additions and 67 deletions

View File

@ -113,8 +113,8 @@ class Keymanager {
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
//here we need the currently logged in user, while userId can be a different user //here we need the currently logged in user, while userId can be a different user
$util = new Util($view, \OCP\User::getUser()); $util = new Util( $view, \OCP\User::getUser() );
list($owner, $filename) = $util->getUidAndFilename($path); list( $owner, $filename ) = $util->getUidAndFilename( $path );
$basePath = '/' . $owner . '/files_encryption/keyfiles'; $basePath = '/' . $owner . '/files_encryption/keyfiles';
@ -123,18 +123,25 @@ class Keymanager {
if ( !$view->is_dir( $basePath . '/' . $targetPath ) ) { if ( !$view->is_dir( $basePath . '/' . $targetPath ) ) {
// create all parent folders // create all parent folders
$info=pathinfo($basePath . '/' . $targetPath); $info = pathinfo( $basePath . '/' . $targetPath );
$keyfileFolderName=$view->getLocalFolder($info['dirname']); $keyfileFolderName = $view->getLocalFolder( $info['dirname'] );
if(!file_exists($keyfileFolderName)) {
mkdir($keyfileFolderName, 0750, true); if ( ! file_exists( $keyfileFolderName ) ) {
mkdir( $keyfileFolderName, 0750, true );
} }
} }
// try reusing key file if part file // try reusing key file if part file
if(self::isPartialFilePath($targetPath)) { if ( self::isPartialFilePath( $targetPath ) ) {
$result = $view->file_put_contents( $basePath . '/' . self::fixPartialFilePath($targetPath) . '.key', $catfile );
$result = $view->file_put_contents( $basePath . '/' . self::fixPartialFilePath( $targetPath ) . '.key', $catfile );
} else { } else {
$result = $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile ); $result = $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile );
} }
\OC_FileProxy::$enabled = $proxyStatus; \OC_FileProxy::$enabled = $proxyStatus;
@ -149,14 +156,15 @@ class Keymanager {
* @return string File path without .part extension * @return string File path without .part extension
* @note this is needed for reusing keys * @note this is needed for reusing keys
*/ */
public static function fixPartialFilePath($path) public static function fixPartialFilePath( $path ) {
{
if (preg_match('/\.part$/', $path)) { if (preg_match('/\.part$/', $path)) {
$newLength = strlen($path) - 5; $newLength = strlen($path) - 5;
$fPath = substr($path, 0, $newLength); $fPath = substr($path, 0, $newLength);
return $fPath; return $fPath;
} else { } else {
return $path; return $path;
@ -165,12 +173,21 @@ class Keymanager {
} }
public static function isPartialFilePath($path) /**
{ * @brief Check if a path is a .part file
if (preg_match('/\.part$/', $path)) { * @param string $path Path that may identify a .part file
* @return bool
*/
public static function isPartialFilePath( $path ) {
if ( preg_match('/\.part$/', $path ) ) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
@ -187,11 +204,16 @@ class Keymanager {
public static function getFileKey( \OC_FilesystemView $view, $userId, $filePath ) { public static function getFileKey( \OC_FilesystemView $view, $userId, $filePath ) {
// try reusing key file if part file // try reusing key file if part file
if(self::isPartialFilePath($filePath)) { if ( self::isPartialFilePath( $filePath ) ) {
$result = self::getFileKey($view, $userId, self::fixPartialFilePath($filePath));
if($result) { $result = self::getFileKey( $view, $userId, self::fixPartialFilePath( $filePath ) );
if ( $result ) {
return $result; return $result;
} }
} }
$util = new Util($view, \OCP\User::getUser()); $util = new Util($view, \OCP\User::getUser());
@ -279,6 +301,7 @@ class Keymanager {
\OC_FileProxy::$enabled = $proxyStatus; \OC_FileProxy::$enabled = $proxyStatus;
return $result; return $result;
} }
/** /**
@ -330,10 +353,10 @@ class Keymanager {
*/ */
public static function setShareKey( \OC_FilesystemView $view, $path, $userId, $shareKey ) { public static function setShareKey( \OC_FilesystemView $view, $path, $userId, $shareKey ) {
//here we need the currently logged in user, while userId can be a different user // Here we need the currently logged in user, while userId can be a different user
$util = new Util( $view, \OCP\User::getUser() ); $util = new Util( $view, \OCP\User::getUser() );
list($owner, $filename) = $util->getUidAndFilename($path); list( $owner, $filename ) = $util->getUidAndFilename( $path );
$basePath = '/' . $owner . '/files_encryption/share-keys'; $basePath = '/' . $owner . '/files_encryption/share-keys';
@ -341,9 +364,13 @@ class Keymanager {
// try reusing key file if part file // try reusing key file if part file
if(self::isPartialFilePath($shareKeyPath)) { if(self::isPartialFilePath($shareKeyPath)) {
$writePath = $basePath . '/' . self::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey'; $writePath = $basePath . '/' . self::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey';
} else { } else {
$writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey'; $writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey';
} }
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
@ -409,10 +436,15 @@ class Keymanager {
// try reusing key file if part file // try reusing key file if part file
if(self::isPartialFilePath($filePath)) { if(self::isPartialFilePath($filePath)) {
$result = self::getShareKey($view, $userId, self::fixPartialFilePath($filePath)); $result = self::getShareKey($view, $userId, self::fixPartialFilePath($filePath));
if($result) { if($result) {
return $result; return $result;
} }
} }
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;