diff options
author | Björn Schießle <bjoern@schiessle.org> | 2013-09-06 17:57:45 +0400 |
---|---|---|
committer | Björn Schießle <bjoern@schiessle.org> | 2013-09-06 17:57:45 +0400 |
commit | 0907b4119af3aec4686d789f06cee0cc33f14c8b (patch) | |
tree | 6ba1c013c1b451eb7b1e38be2228dd6cd73bf161 | |
parent | 2d1d8465e89a9e064b15b19f9591ef4c04480160 (diff) | |
parent | 1d2f44412818ed1f918a9bb7bdc0377bd33ad685 (diff) |
Merge pull request #4551 from owncloud/fix_4533
Handle part files correctly
-rwxr-xr-x | apps/files_encryption/lib/keymanager.php | 28 | ||||
-rw-r--r-- | apps/files_encryption/lib/stream.php | 28 | ||||
-rw-r--r-- | apps/files_encryption/lib/util.php | 44 | ||||
-rw-r--r-- | lib/public/share.php | 9 |
4 files changed, 60 insertions, 49 deletions
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index b2fd650f18d..0304d1134c4 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -220,22 +220,10 @@ class Keymanager { */ public static function getFileKey(\OC_FilesystemView $view, $userId, $filePath) { - // try reusing key file if part file - if (self::isPartialFilePath($filePath)) { - - $result = self::getFileKey($view, $userId, self::fixPartialFilePath($filePath)); - - if ($result) { - - return $result; - - } - - } - $util = new Util($view, \OCP\User::getUser()); list($owner, $filename) = $util->getUidAndFilename($filePath); + $filename = self::fixPartialFilePath($filename); $filePath_f = ltrim($filename, '/'); // in case of system wide mount points the keys are stored directly in the data directory @@ -424,18 +412,6 @@ class Keymanager { public static function getShareKey(\OC_FilesystemView $view, $userId, $filePath) { // try reusing key file if part file - if (self::isPartialFilePath($filePath)) { - - $result = self::getShareKey($view, $userId, self::fixPartialFilePath($filePath)); - - if ($result) { - - return $result; - - } - - } - $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; @@ -443,7 +419,7 @@ class Keymanager { $util = new Util($view, \OCP\User::getUser()); list($owner, $filename) = $util->getUidAndFilename($filePath); - + $filename = self::fixPartialFilePath($filename); // in case of system wide mount points the keys are stored directly in the data directory if ($util->isSystemWideMountPoint($filename)) { $shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey'; diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 3c1eb2c5f5e..08024b8090d 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -175,7 +175,7 @@ class Stream { } // Get the data from the file handle - $data = fread($this->handle, 8192); + $data = fread($this->handle, $count); $result = null; @@ -281,9 +281,9 @@ class Stream { return strlen($data); } - // Disable the file proxies so that encryption is not - // automatically attempted when the file is written to disk - - // we are handling that separately here and we don't want to + // Disable the file proxies so that encryption is not + // automatically attempted when the file is written to disk - + // we are handling that separately here and we don't want to // get into an infinite loop $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; @@ -296,7 +296,7 @@ class Stream { $pointer = ftell($this->handle); // Get / generate the keyfile for the file we're handling - // If we're writing a new file (not overwriting an existing + // If we're writing a new file (not overwriting an existing // one), save the newly generated keyfile if (!$this->getKey()) { @@ -304,7 +304,7 @@ class Stream { } - // If extra data is left over from the last round, make sure it + // If extra data is left over from the last round, make sure it // is integrated into the next 6126 / 8192 block if ($this->writeCache) { @@ -329,12 +329,12 @@ class Stream { if ($remainingLength < 6126) { // Set writeCache to contents of $data - // The writeCache will be carried over to the - // next write round, and added to the start of - // $data to ensure that written blocks are - // always the correct length. If there is still - // data in writeCache after the writing round - // has finished, then the data will be written + // The writeCache will be carried over to the + // next write round, and added to the start of + // $data to ensure that written blocks are + // always the correct length. If there is still + // data in writeCache after the writing round + // has finished, then the data will be written // to disk by $this->flush(). $this->writeCache = $data; @@ -348,7 +348,7 @@ class Stream { $encrypted = $this->preWriteEncrypt($chunk, $this->plainKey); - // Write the data chunk to disk. This will be + // Write the data chunk to disk. This will be // attended to the last data chunk if the file // being handled totals more than 6126 bytes fwrite($this->handle, $encrypted); @@ -475,6 +475,7 @@ class Stream { and $this->meta['mode'] !== 'rb' and $this->size > 0 ) { + // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; @@ -518,6 +519,7 @@ class Stream { // set fileinfo $this->rootView->putFileInfo($this->rawPath, $fileInfo); + } return fclose($this->handle); diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index aa2d7657a65..a2aa305b64c 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -588,10 +588,11 @@ class Util { // get the size from filesystem $fullPath = $this->view->getLocalFile($path); - $size = filesize($fullPath); + $size = $this->view->filesize($path); // calculate last chunk nr $lastChunkNr = floor($size / 8192); + $lastChunkSize = $size - ($lastChunkNr * 8192); // open stream $stream = fopen('crypt://' . $relativePath, "r"); @@ -604,7 +605,7 @@ class Util { fseek($stream, $lastChunckPos); // get the content of the last chunk - $lastChunkContent = fread($stream, 8192); + $lastChunkContent = fread($stream, $lastChunkSize); // calc the real file size with the size of the last chunk $realSize = (($lastChunkNr * 6126) + strlen($lastChunkContent)); @@ -1018,6 +1019,11 @@ class Util { // Make sure that a share key is generated for the owner too list($owner, $ownerPath) = $this->getUidAndFilename($filePath); + $pathinfo = pathinfo($ownerPath); + if(array_key_exists('extension', $pathinfo) && $pathinfo['extension'] === 'part') { + $ownerPath = $pathinfo['dirname'] . '/' . $pathinfo['filename']; + } + $userIds = array(); if ($sharingEnabled) { @@ -1171,8 +1177,25 @@ class Util { */ public function getUidAndFilename($path) { + $pathinfo = pathinfo($path); + $partfile = false; + $parentFolder = false; + if (array_key_exists('extension', $pathinfo) && $pathinfo['extension'] === 'part') { + // if the real file exists we check this file + $filePath = $this->userFilesDir . '/' .$pathinfo['dirname'] . '/' . $pathinfo['filename']; + if ($this->view->file_exists($filePath)) { + $pathToCheck = $pathinfo['dirname'] . '/' . $pathinfo['filename']; + } else { // otherwise we look for the parent + $pathToCheck = $pathinfo['dirname']; + $parentFolder = true; + } + $partfile = true; + } else { + $pathToCheck = $path; + } + $view = new \OC\Files\View($this->userFilesDir); - $fileOwnerUid = $view->getOwner($path); + $fileOwnerUid = $view->getOwner($pathToCheck); // handle public access if ($this->isPublic) { @@ -1201,12 +1224,18 @@ class Util { $filename = $path; } else { - - $info = $view->getFileInfo($path); + $info = $view->getFileInfo($pathToCheck); $ownerView = new \OC\Files\View('/' . $fileOwnerUid . '/files'); // Fetch real file path from DB - $filename = $ownerView->getPath($info['fileid']); // TODO: Check that this returns a path without including the user data dir + $filename = $ownerView->getPath($info['fileid']); + if ($parentFolder) { + $filename = $filename . '/'. $pathinfo['filename']; + } + + if ($partfile) { + $filename = $filename . '.' . $pathinfo['extension']; + } } @@ -1215,10 +1244,9 @@ class Util { \OC_Filesystem::normalizePath($filename) ); } - - } + /** * @brief go recursively through a dir and collect all files and sub files. * @param string $dir relative to the users files folder diff --git a/lib/public/share.php b/lib/public/share.php index cae0e3bdc04..83dc6b82b19 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -141,8 +141,13 @@ class Share { $source = -1; $cache = false; - $view = new \OC\Files\View('/' . $user . '/files/'); - $meta = $view->getFileInfo(\OC\Files\Filesystem::normalizePath($path)); + $view = new \OC\Files\View('/' . $user . '/files'); + if ($view->file_exists($path)) { + $meta = $view->getFileInfo($path); + } else { + // if the file doesn't exists yet we start with the parent folder + $meta = $view->getFileInfo(dirname($path)); + } if($meta !== false) { $source = $meta['fileid']; |