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,19 +123,26 @@ 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 );
} else { $result = $view->file_put_contents( $basePath . '/' . self::fixPartialFilePath( $targetPath ) . '.key', $catfile );
$result = $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile );
} } else {
$result = $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile );
}
\OC_FileProxy::$enabled = $proxyStatus; \OC_FileProxy::$enabled = $proxyStatus;
@ -143,37 +150,47 @@ class Keymanager {
} }
/** /**
* @brief Remove .path extension from a file path * @brief Remove .path extension from a file path
* @param string $path Path that may identify a .part file * @param string $path Path that may identify a .part file
* @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;
} }
} }
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 true; * @return bool
} else { */
return false; public static function isPartialFilePath( $path ) {
}
if ( preg_match('/\.part$/', $path ) ) {
return true;
} else {
return false;
}
} }
/** /**
* @brief retrieve keyfile for an encrypted file * @brief retrieve keyfile for an encrypted file
* @param \OC_FilesystemView $view * @param \OC_FilesystemView $view
@ -186,21 +203,26 @@ 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 ) );
return $result;
} if ( $result ) {
}
return $result;
}
}
$util = new Util($view, \OCP\User::getUser()); $util = new Util($view, \OCP\User::getUser());
list($owner, $filename) = $util->getUidAndFilename($filePath); list($owner, $filename) = $util->getUidAndFilename($filePath);
$filePath_f = ltrim( $filename, '/' ); $filePath_f = ltrim( $filename, '/' );
$keyfilePath = '/' . $owner . '/files_encryption/keyfiles/' . $filePath_f . '.key'; $keyfilePath = '/' . $owner . '/files_encryption/keyfiles/' . $filePath_f . '.key';
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
if ( $view->file_exists( $keyfilePath ) ) { if ( $view->file_exists( $keyfilePath ) ) {
@ -269,7 +291,7 @@ class Keymanager {
$view = new \OC_FilesystemView( '/' . $user . '/files_encryption' ); $view = new \OC_FilesystemView( '/' . $user . '/files_encryption' );
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
if ( !$view->file_exists( '' ) ) $view->mkdir( '' ); if ( !$view->file_exists( '' ) ) $view->mkdir( '' );
@ -278,7 +300,8 @@ class Keymanager {
\OC_FileProxy::$enabled = $proxyStatus; \OC_FileProxy::$enabled = $proxyStatus;
return $result; return $result;
} }
/** /**
@ -304,7 +327,7 @@ class Keymanager {
$view = new \OC_FilesystemView( '/public-keys' ); $view = new \OC_FilesystemView( '/public-keys' );
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
if ( !$view->file_exists( '' ) ) $view->mkdir( '' ); if ( !$view->file_exists( '' ) ) $view->mkdir( '' );
@ -313,7 +336,7 @@ class Keymanager {
\OC_FileProxy::$enabled = $proxyStatus; \OC_FileProxy::$enabled = $proxyStatus;
return $result; return $result;
} }
@ -330,28 +353,32 @@ 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';
$shareKeyPath = self::keySetPreparation( $view, $filename, $basePath, $owner ); $shareKeyPath = self::keySetPreparation( $view, $filename, $basePath, $owner );
// 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';
} else { $writePath = $basePath . '/' . self::fixPartialFilePath($shareKeyPath) . '.' . $userId . '.shareKey';
$writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey';
} } else {
$writePath = $basePath . '/' . $shareKeyPath . '.' . $userId . '.shareKey';
}
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
$result = $view->file_put_contents( $writePath, $shareKey ); $result = $view->file_put_contents( $writePath, $shareKey );
\OC_FileProxy::$enabled = $proxyStatus; \OC_FileProxy::$enabled = $proxyStatus;
if ( if (
is_int( $result ) is_int( $result )
@ -407,15 +434,20 @@ class Keymanager {
*/ */
public static function getShareKey( \OC_FilesystemView $view, $userId, $filePath ) { public static function getShareKey( \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::getShareKey($view, $userId, self::fixPartialFilePath($filePath));
if($result) { $result = self::getShareKey($view, $userId, self::fixPartialFilePath($filePath));
return $result;
} if($result) {
}
return $result;
}
}
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
\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