Improvements to code formatting & indentation

This commit is contained in:
Sam Tuke 2013-05-09 18:16:59 +02:00
parent 3003dd46d1
commit 92e28839ff
1 changed files with 122 additions and 117 deletions

View File

@ -305,7 +305,6 @@ class Util {
* @brief Find all files and their encryption status within a directory * @brief Find all files and their encryption status within a directory
* @param string $directory The path of the parent directory to search * @param string $directory The path of the parent directory to search
* @return mixed false if 0 found, array on success. Keys: name, path * @return mixed false if 0 found, array on success. Keys: name, path
* @note $directory needs to be a path relative to OC data dir. e.g. * @note $directory needs to be a path relative to OC data dir. e.g.
* /admin/files NOT /backup OR /home/www/oc/data/admin/files * /admin/files NOT /backup OR /home/www/oc/data/admin/files
*/ */
@ -444,10 +443,10 @@ class Util {
return $text; return $text;
} }
/** /**
* @brief Check if a given path identifies an encrypted file * @brief Check if a given path identifies an encrypted file
* @return true / false * @return true / false
*/ */
public function isEncryptedPath( $path ) { public function isEncryptedPath( $path ) {
// Disable encryption proxy so data retreived is in its // Disable encryption proxy so data retreived is in its
@ -462,89 +461,94 @@ class Util {
} }
/** /**
* @brief get the file size of the unencrypted file * @brief get the file size of the unencrypted file
* @param $path absolute path * @param $path absolute path
* @return bool * @return bool
*/ */
public function getFileSize($path) { public function getFileSize( $path ) {
$result = 0;
$result = 0;
// Disable encryption proxy to prevent recursive calls // Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
// Reformat path for use with OC_FSV // Reformat path for use with OC_FSV
$pathSplit = explode( '/', $path ); $pathSplit = explode( '/', $path );
$pathRelative = implode( '/', array_slice( $pathSplit, 3 ) ); $pathRelative = implode( '/', array_slice( $pathSplit, 3 ) );
if ($pathSplit[2] == 'files' && $this->view->file_exists($path) && $this->isEncryptedPath($path)) { if ($pathSplit[2] == 'files' && $this->view->file_exists($path) && $this->isEncryptedPath($path)) {
// get the size from filesystem // get the size from filesystem
$fullPath = $this->view->getLocalFile($path); $fullPath = $this->view->getLocalFile($path);
$size = filesize($fullPath); $size = filesize($fullPath);
// calculate last chunk nr // calculate last chunk nr
$lastChunckNr = floor($size / 8192); $lastChunckNr = floor($size / 8192);
// open stream // open stream
$stream = fopen('crypt://' . $pathRelative, "r"); $stream = fopen('crypt://' . $pathRelative, "r");
if(is_resource($stream)) { if(is_resource($stream)) {
// calculate last chunk position // calculate last chunk position
$lastChunckPos = ($lastChunckNr * 8192); $lastChunckPos = ($lastChunckNr * 8192);
// seek to end // seek to end
fseek($stream, $lastChunckPos); fseek($stream, $lastChunckPos);
// get the content of the last chunk // get the content of the last chunk
$lastChunkContent = fread($stream, 8192); $lastChunkContent = fread($stream, 8192);
// calc the real file size with the size of the last chunk // calc the real file size with the size of the last chunk
$realSize = (($lastChunckNr * 6126) + strlen($lastChunkContent)); $realSize = (($lastChunckNr * 6126) + strlen($lastChunkContent));
// store file size // store file size
$result = $realSize; $result = $realSize;
} }
} }
\OC_FileProxy::$enabled = $proxyStatus; \OC_FileProxy::$enabled = $proxyStatus;
return $result; return $result;
} }
/**
* @brief fix the file size of the encrypted file /**
* * @brief fix the file size of the encrypted file
* @param $path absolute path * @param $path absolute path
* @return true / false if file is encrypted * @return true / false if file is encrypted
*/ */
public function fixFileSize($path) { public function fixFileSize( $path ) {
$result = false;
$result = false;
// Disable encryption proxy to prevent recursive calls // Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled; $proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false; \OC_FileProxy::$enabled = false;
$realSize = $this->getFileSize($path); $realSize = $this->getFileSize( $path );
if($realSize > 0) {
$cached = $this->view->getFileInfo($path); if ( $realSize > 0 ) {
$cached['encrypted'] = 1;
$cached = $this->view->getFileInfo( $path );
$cached['encrypted'] = 1;
// set the size // set the size
$cached['unencrypted_size'] = $realSize; $cached['unencrypted_size'] = $realSize;
// put file info // put file info
$this->view->putFileInfo( $path, $cached ); $this->view->putFileInfo( $path, $cached );
$result = true; $result = true;
}
}
\OC_FileProxy::$enabled = $proxyStatus; \OC_FileProxy::$enabled = $proxyStatus;
return $result; return $result;
} }
/** /**
* @brief Format a path to be relative to the /user/files/ directory * @brief Format a path to be relative to the /user/files/ directory
@ -640,7 +644,7 @@ class Util {
stream_copy_to_stream( $plainHandle1, $plainHandle2 ); stream_copy_to_stream( $plainHandle1, $plainHandle2 );
// Close access to original file // Close access to original file
// $this->view->fclose( $plainHandle1 ); // not implemented in view{} // $this->view->fclose( $plainHandle1 ); // not implemented in view{}
// Delete original plain file so we can rename enc file later // Delete original plain file so we can rename enc file later
$this->view->unlink( $rawPath ); $this->view->unlink( $rawPath );
@ -1156,64 +1160,65 @@ class Util {
} }
/** /**
* @brief get shares parent. * @brief get shares parent.
* @param int $id of the current share * @param int $id of the current share
* @return array of the parent * @return array of the parent
*/ */
public static function getShareParent( $id ) { public static function getShareParent( $id ) {
$query = \OC_DB::prepare( 'SELECT `file_target`, `item_type`' $query = \OC_DB::prepare( 'SELECT `file_target`, `item_type`'
.' FROM `*PREFIX*share`' .' FROM `*PREFIX*share`'
.' WHERE `id` = ?' ); .' WHERE `id` = ?' );
$result = $query->execute( array( $id ) ); $result = $query->execute( array( $id ) );
$row = $result->fetchRow(); $row = $result->fetchRow();
return $row; return $row;
}
/**
* @brief get owner of the shared files.
* @param int $Id of a share
* @return owner
*/
public function getOwnerFromSharedFile($id) {
$query = \OC_DB::prepare( 'SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1 );
$source = $query->execute( array( $id ) )->fetchRow();
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'];
} }
/**
* @brief get owner of the shared files.
* @param int $Id of a share
* @return owner
*/
public function getOwnerFromSharedFile( $id ) {
$query = \OC_DB::prepare( 'SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1 );
$source = $query->execute( array( $id ) )->fetchRow();
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'];
}
return $fileOwner; return $fileOwner;
} }
} }