improved rename and file size support
fix missing user_id on write
This commit is contained in:
parent
9a0b73070c
commit
6b47da10be
|
@ -288,7 +288,8 @@ class Proxy extends \OC_FileProxy {
|
|||
* @return bool Result of rename()
|
||||
* @note This is pre rather than post because using post didn't work
|
||||
*/
|
||||
public function preRename( $oldPath, $newPath ) {
|
||||
public function preRename( $oldPath, $newPath )
|
||||
{
|
||||
|
||||
// Disable encryption proxy to prevent recursive calls
|
||||
\OC_FileProxy::$enabled = false;
|
||||
|
@ -302,13 +303,28 @@ class Proxy extends \OC_FileProxy {
|
|||
$oldSplit = explode('/', $oldTrimmed);
|
||||
$oldSliced = array_slice($oldSplit, 2);
|
||||
$oldRelPath = implode('/', $oldSliced);
|
||||
$oldKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $oldRelPath . '.key';
|
||||
$oldKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $oldRelPath;
|
||||
|
||||
|
||||
$newTrimmed = ltrim($newPath, '/');
|
||||
$newSplit = explode('/', $newTrimmed);
|
||||
$newSliced = array_slice($newSplit, 2);
|
||||
$newRelPath = implode('/', $newSliced);
|
||||
$newKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $newRelPath . '.key';
|
||||
$newKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $newRelPath;
|
||||
|
||||
// add key ext if this is not an folder
|
||||
if (!$view->is_dir($oldKeyfilePath)) {
|
||||
$oldKeyfilePath .= '.key';
|
||||
$newKeyfilePath .= '.key';
|
||||
} else {
|
||||
// handle share-keys folders
|
||||
$oldShareKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $oldRelPath;
|
||||
$newShareKeyfilePath = $userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $newRelPath;
|
||||
$view->rename($oldShareKeyfilePath, $newShareKeyfilePath);
|
||||
}
|
||||
|
||||
//TODO add support for share-keys files
|
||||
//...
|
||||
|
||||
// Rename keyfile so it isn't orphaned
|
||||
$result = $view->rename($oldKeyfilePath, $newKeyfilePath);
|
||||
|
@ -426,7 +442,11 @@ class Proxy extends \OC_FileProxy {
|
|||
$path_split = explode('/', $path);
|
||||
$path_f = implode('/', array_slice($path_split, 3));
|
||||
|
||||
if ( Crypt::isEncryptedMeta( $path_f ) ) {
|
||||
$view = new \OC_FilesystemView( '/' );
|
||||
$userId = \OCP\User::getUser();
|
||||
$util = new Util( $view, $userId );
|
||||
|
||||
if ($util->isEncryptedPath($path)) {
|
||||
|
||||
// Disable encryption proxy to prevent recursive calls
|
||||
\OC_FileProxy::$enabled = false;
|
||||
|
@ -440,6 +460,7 @@ class Proxy extends \OC_FileProxy {
|
|||
// open stream
|
||||
$result = fopen('crypt://' . $path_f, "r");
|
||||
|
||||
if(is_resource($result)) {
|
||||
// calculate last chunk position
|
||||
$lastChunckPos = ($lastChunckNr * 8192);
|
||||
|
||||
|
@ -452,11 +473,12 @@ class Proxy extends \OC_FileProxy {
|
|||
// calc the real file size with the size of the last chunk
|
||||
$realSize = (($lastChunckNr * 6126) + strlen($lastChunkContent));
|
||||
|
||||
// enable proxy
|
||||
\OC_FileProxy::$enabled = true;
|
||||
|
||||
// set the size
|
||||
$cached['size'] = $realSize;
|
||||
}
|
||||
|
||||
// enable proxy
|
||||
\OC_FileProxy::$enabled = true;
|
||||
|
||||
return $cached['size'];
|
||||
|
||||
|
|
|
@ -101,6 +101,9 @@ class Stream {
|
|||
|
||||
} else {
|
||||
|
||||
// Disable fileproxies so we can get the file size and open the source file without recursive encryption
|
||||
\OC_FileProxy::$enabled = false;
|
||||
|
||||
if (
|
||||
$mode == 'w'
|
||||
or $mode == 'w+'
|
||||
|
@ -119,9 +122,6 @@ class Stream {
|
|||
|
||||
}
|
||||
|
||||
// Disable fileproxies so we can open the source file without recursive encryption
|
||||
\OC_FileProxy::$enabled = false;
|
||||
|
||||
//$this->handle = fopen( $this->rawPath, $mode );
|
||||
|
||||
$this->handle = $this->rootView->fopen( $this->rawPath, $mode );
|
||||
|
@ -241,13 +241,12 @@ class Stream {
|
|||
// Avoid problems with .part file extensions
|
||||
$this->relPath = Keymanager::fixPartialFilePath( $this->relPath );
|
||||
|
||||
// If a keyfile already exists
|
||||
if ( $this->rootView->file_exists( $this->userId . '/'. 'files_encryption' . '/' . 'keyfiles' . '/' . $this->relPath . '.key' ) ) {
|
||||
|
||||
// Fetch and decrypt keyfile
|
||||
// Fetch existing keyfile
|
||||
$this->encKeyfile = Keymanager::getFileKey( $this->rootView, $this->userId, $this->relPath );
|
||||
|
||||
// If a keyfile already exists
|
||||
if ( $this->encKeyfile ) {
|
||||
$this->setUserProperty();
|
||||
|
||||
$session = new Session( $this->rootView );
|
||||
|
@ -339,6 +338,10 @@ class Stream {
|
|||
// Get all users sharing the file
|
||||
$uniqueUserIds = $util->getSharingUsersArray( $sharingEnabled, $this->relPath );
|
||||
|
||||
// allways add current user
|
||||
$uniqueUserIds[] = $this->userId;
|
||||
array_unique( $uniqueUserIds );
|
||||
|
||||
// Fetch public keys for all sharing users
|
||||
$publicKeys = Keymanager::getPublicKeys( $this->rootView, $uniqueUserIds );
|
||||
|
||||
|
@ -429,7 +432,7 @@ class Stream {
|
|||
|
||||
$encrypted = $this->preWriteEncrypt( $chunk, $this->plainKey );
|
||||
|
||||
trigger_error("\$encrypted = $encrypted");
|
||||
//trigger_error("\$encrypted = $encrypted");
|
||||
|
||||
// Write the data chunk to disk. This will be
|
||||
// attended to the last data chunk if the file
|
||||
|
|
Loading…
Reference in New Issue