implement postRename
@samtuke no need anymore for fixPartialFilePath this is now handled by rename share-keys are now handled properly webdav .part files are handled properly
This commit is contained in:
parent
672d177f10
commit
8ee7959092
|
@ -139,28 +139,6 @@ class Keymanager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Remove .path extension from a file path
|
|
||||||
* @param string $path Path that may identify a .part file
|
|
||||||
* @return string File path without .part extension
|
|
||||||
*/
|
|
||||||
public static function fixPartialFilePath( $path ) {
|
|
||||||
|
|
||||||
if ( preg_match( '/\.part$/', $path ) ) {
|
|
||||||
|
|
||||||
$newLength = strlen( $path ) - 5;
|
|
||||||
$fPath = substr( $path, 0, $newLength );
|
|
||||||
|
|
||||||
return $fPath;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return $path;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief retrieve keyfile for an encrypted file
|
* @brief retrieve keyfile for an encrypted file
|
||||||
* @param \OC_FilesystemView $view
|
* @param \OC_FilesystemView $view
|
||||||
|
|
|
@ -237,8 +237,6 @@ class Proxy extends \OC_FileProxy {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = Keymanager::fixPartialFilePath( $path );
|
|
||||||
|
|
||||||
// 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;
|
||||||
|
@ -307,6 +305,15 @@ class Proxy extends \OC_FileProxy {
|
||||||
if (!$view->is_dir($oldKeyfilePath)) {
|
if (!$view->is_dir($oldKeyfilePath)) {
|
||||||
$oldKeyfilePath .= '.key';
|
$oldKeyfilePath .= '.key';
|
||||||
$newKeyfilePath .= '.key';
|
$newKeyfilePath .= '.key';
|
||||||
|
|
||||||
|
// handle share-keys
|
||||||
|
$localKeyPath = $view->getLocalFile($userId.'/files_encryption/share-keys/'.$oldRelPath);
|
||||||
|
$matches = glob(preg_quote($localKeyPath).'*.shareKey');
|
||||||
|
foreach ($matches as $src) {
|
||||||
|
$dst = str_replace($oldRelPath, $newRelPath, $src);
|
||||||
|
rename($src, $dst);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// handle share-keys folders
|
// handle share-keys folders
|
||||||
$oldShareKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $oldRelPath;
|
$oldShareKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $oldRelPath;
|
||||||
|
@ -314,9 +321,6 @@ class Proxy extends \OC_FileProxy {
|
||||||
$view->rename($oldShareKeyfilePath, $newShareKeyfilePath);
|
$view->rename($oldShareKeyfilePath, $newShareKeyfilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO add support for share-keys files
|
|
||||||
//...
|
|
||||||
|
|
||||||
// Rename keyfile so it isn't orphaned
|
// Rename keyfile so it isn't orphaned
|
||||||
$result = $view->rename($oldKeyfilePath, $newKeyfilePath);
|
$result = $view->rename($oldKeyfilePath, $newKeyfilePath);
|
||||||
|
|
||||||
|
@ -326,6 +330,70 @@ class Proxy extends \OC_FileProxy {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief When a file is renamed, rename its keyfile also
|
||||||
|
* @return bool Result of rename()
|
||||||
|
* @note This is pre rather than post because using post didn't work
|
||||||
|
*/
|
||||||
|
public function postRename( $oldPath, $newPath )
|
||||||
|
{
|
||||||
|
|
||||||
|
// Disable encryption proxy to prevent recursive calls
|
||||||
|
$proxyStatus = \OC_FileProxy::$enabled;
|
||||||
|
\OC_FileProxy::$enabled = false;
|
||||||
|
|
||||||
|
$view = new \OC_FilesystemView('/');
|
||||||
|
$userId = \OCP\User::getUser();
|
||||||
|
$util = new Util( $view, $userId );
|
||||||
|
|
||||||
|
// Reformat path for use with OC_FSV
|
||||||
|
$newPathSplit = explode( '/', $newPath );
|
||||||
|
$newPathRelative = implode( '/', array_slice( $newPathSplit, 3 ) );
|
||||||
|
$newPathRelativeToUser = implode( '/', array_slice( $newPathSplit, 2 ) );
|
||||||
|
|
||||||
|
// get file info from database/cache
|
||||||
|
//$newFileInfo = \OC\Files\Filesystem::getFileInfo($newPathRelative);
|
||||||
|
|
||||||
|
if ($util->isEncryptedPath($newPath)) {
|
||||||
|
$cached = $view->getFileInfo($newPath);
|
||||||
|
$cached['encrypted'] = 1;
|
||||||
|
|
||||||
|
// get the size from filesystem
|
||||||
|
$size = $view->filesize($newPath);
|
||||||
|
|
||||||
|
// calculate last chunk nr
|
||||||
|
$lastChunckNr = floor($size / 8192);
|
||||||
|
|
||||||
|
// open stream
|
||||||
|
$result = fopen('crypt://' . $newPathRelative, "r");
|
||||||
|
|
||||||
|
if(is_resource($result)) {
|
||||||
|
// calculate last chunk position
|
||||||
|
$lastChunckPos = ($lastChunckNr * 8192);
|
||||||
|
|
||||||
|
// seek to end
|
||||||
|
fseek($result, $lastChunckPos);
|
||||||
|
|
||||||
|
// get the content of the last chunck
|
||||||
|
$lastChunkContent = fread($result, 8192);
|
||||||
|
|
||||||
|
// calc the real file size with the size of the last chunk
|
||||||
|
$realSize = (($lastChunckNr * 6126) + strlen($lastChunkContent));
|
||||||
|
|
||||||
|
// set the size
|
||||||
|
$cached['unencrypted_size'] = $realSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
$view->putFileInfo( $newPath, $cached );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
\OC_FileProxy::$enabled = $proxyStatus;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function postFopen( $path, &$result ){
|
public function postFopen( $path, &$result ){
|
||||||
|
|
||||||
if ( !$result ) {
|
if ( !$result ) {
|
||||||
|
@ -424,11 +492,11 @@ class Proxy extends \OC_FileProxy {
|
||||||
|
|
||||||
// if path is a folder do nothing
|
// if path is a folder do nothing
|
||||||
if(is_array($data) && array_key_exists('size', $data)) {
|
if(is_array($data) && array_key_exists('size', $data)) {
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
|
|
||||||
// get file size
|
// get file size
|
||||||
$data['size'] = self::postFileSize($path, $data['size']);
|
$data['size'] = self::postFileSize($path, $data['size']);
|
||||||
|
|
||||||
|
@ -461,8 +529,6 @@ class Proxy extends \OC_FileProxy {
|
||||||
return $size;
|
return $size;
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = Keymanager::fixPartialFilePath( $path );
|
|
||||||
|
|
||||||
// Reformat path for use with OC_FSV
|
// Reformat path for use with OC_FSV
|
||||||
$path_split = explode('/', $path);
|
$path_split = explode('/', $path);
|
||||||
$path_f = implode('/', array_slice($path_split, 3));
|
$path_f = implode('/', array_slice($path_split, 3));
|
||||||
|
@ -474,7 +540,7 @@ class Proxy extends \OC_FileProxy {
|
||||||
if(is_array($fileInfo) && $fileInfo['encrypted'] == 1) {
|
if(is_array($fileInfo) && $fileInfo['encrypted'] == 1) {
|
||||||
return $fileInfo['unencrypted_size'];
|
return $fileInfo['unencrypted_size'];
|
||||||
} else {
|
} else {
|
||||||
return $fileInfo['size'];
|
return $size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,9 +87,6 @@ class Stream {
|
||||||
// rawPath is relative to the data directory
|
// rawPath is relative to the data directory
|
||||||
$this->rawPath = $this->userId . '/files/' . $this->relPath;
|
$this->rawPath = $this->userId . '/files/' . $this->relPath;
|
||||||
|
|
||||||
// Fix .part filenames
|
|
||||||
$this->rawPath = Keymanager::fixPartialFilePath( $this->rawPath );
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
dirname( $this->rawPath ) == 'streams'
|
dirname( $this->rawPath ) == 'streams'
|
||||||
and isset( self::$sourceStreams[basename( $this->rawPath )] )
|
and isset( self::$sourceStreams[basename( $this->rawPath )] )
|
||||||
|
@ -244,9 +241,6 @@ class Stream {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid problems with .part file extensions
|
|
||||||
$this->relPath = Keymanager::fixPartialFilePath( $this->relPath );
|
|
||||||
|
|
||||||
// Fetch and decrypt keyfile
|
// Fetch and decrypt keyfile
|
||||||
// Fetch existing keyfile
|
// Fetch existing keyfile
|
||||||
$this->encKeyfile = Keymanager::getFileKey( $this->rootView, $this->userId, $this->relPath );
|
$this->encKeyfile = Keymanager::getFileKey( $this->rootView, $this->userId, $this->relPath );
|
||||||
|
|
Loading…
Reference in New Issue