aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-05-24 17:35:00 +0200
committerBjörn Schießle <schiessle@owncloud.com>2013-05-24 20:02:41 +0200
commit397dc3dcde165c1926e139b042e72baf8717c695 (patch)
tree1a11dd61f85dcba129d21a27ebc2dc68de828be8 /apps
parent8c235de8266639d01e1ac75946e5d2f572992d96 (diff)
downloadnextcloud-server-397dc3dcde165c1926e139b042e72baf8717c695.tar.gz
nextcloud-server-397dc3dcde165c1926e139b042e72baf8717c695.zip
fix first time encryption after app was enabled
Diffstat (limited to 'apps')
-rw-r--r--apps/files_encryption/lib/util.php35
1 files changed, 12 insertions, 23 deletions
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 2980aa94e0c..cac67d496e8 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -421,7 +421,7 @@ class Util
// If the file uses old
// encryption system
- } elseif ( Crypt::isLegacyEncryptedContent( $this->tail( $filePath, 3 ), $relPath ) ) {
+ } elseif ( Crypt::isLegacyEncryptedContent( $data, $relPath ) ) {
$found['legacy'][] = array( 'name' => $file, 'path' => $filePath );
@@ -672,39 +672,28 @@ class Util
$relPath = $plainFile['path'];
//relative to /data
- $rawPath = $this->userId . '/files/' . $plainFile['path'];
+ $rawPath = '/'.$this->userId . '/files/' . $plainFile['path'];
// Open plain file handle for binary reading
- $plainHandle1 = $this->view->fopen( $rawPath, 'rb' );
+ $plainHandle = $this->view->fopen( $rawPath, 'rb' );
- // 2nd handle for moving plain file - view->rename() doesn't work, this is a workaround
- $plainHandle2 = $this->view->fopen( $rawPath . '.plaintmp', 'wb' );
+ // Open enc file handle for binary writing, with same filename as original plain file
+ $encHandle = fopen( 'crypt://' . $relPath.'.tmp', 'wb' );
// Move plain file to a temporary location
- stream_copy_to_stream( $plainHandle1, $plainHandle2 );
-
- // Close access to original file
- // $this->view->fclose( $plainHandle1 ); // not implemented in view{}
- // Delete original plain file so we can rename enc file later
- $this->view->unlink( $rawPath );
+ $size = stream_copy_to_stream( $plainHandle, $encHandle );
- // Open enc file handle for binary writing, with same filename as original plain file
- $encHandle = fopen( 'crypt://' . $relPath, 'wb' );
+ fclose($encHandle);
- // Save data from plain stream to new encrypted file via enc stream
- // NOTE: Stream{} will be invoked for handling
- // the encryption, and should handle all keys
- // and their generation etc. automatically
- stream_copy_to_stream( $plainHandle2, $encHandle );
+ $fakeRoot = $this->view->getRoot();
+ $this->view->chroot('/'.$this->userId.'/files');
- // get file size
- $size = $this->view->filesize( $rawPath . '.plaintmp' );
+ $this->view->rename($relPath . '.tmp', $relPath);
- // Delete temporary plain copy of file
- $this->view->unlink( $rawPath . '.plaintmp' );
+ $this->view->chroot($fakeRoot);
// Add the file to the cache
- \OC\Files\Filesystem::putFileInfo( $plainFile['path'], array( 'encrypted' => true, 'size' => $size, 'unencrypted_size' => $size ) );
+ \OC\Files\Filesystem::putFileInfo( $relPath, array( 'encrypted' => true, 'size' => $size, 'unencrypted_size' => $size ) );
}
// Encrypt legacy encrypted files