diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php
index 3af43f10264240f8a37ea7dab51982ed61aeb2b6..0b6c5adf3fb613ef9a0a9f7265b69bafd09e57ff 100644
--- a/apps/files_encryption/hooks/hooks.php
+++ b/apps/files_encryption/hooks/hooks.php
@@ -501,11 +501,20 @@ class Hooks {
 	 * @param array $params with the old path and the new path
 	 */
 	public static function preRename($params) {
-		$util = new Util(new \OC_FilesystemView('/'), \OCP\User::getUser());
+		$user = \OCP\User::getUser();
+		$view = new \OC_FilesystemView('/');
+		$util = new Util($view, $user);
 		list($ownerOld, $pathOld) = $util->getUidAndFilename($params['oldpath']);
-		self::$renamedFiles[$params['oldpath']] = array(
-			'uid' => $ownerOld,
-			'path' => $pathOld);
+
+		// we only need to rename the keys if the rename happens on the same mountpoint
+		// otherwise we perform a stream copy, so we get a new set of keys
+		$mp1 = $view->getMountPoint('/' . $user . '/files/' . $params['oldpath']);
+		$mp2 = $view->getMountPoint('/' . $user . '/files/' . $params['newpath']);
+		if ($mp1 === $mp2) {
+			self::$renamedFiles[$params['oldpath']] = array(
+				'uid' => $ownerOld,
+				'path' => $pathOld);
+		}
 	}
 
 	/**
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 530aa8f7514df6b87970d6b2684c7279f32315b0..e2c565c5cbba25bd3f2b162e114e03879c9dcb5a 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -534,6 +534,8 @@ class View {
 						$source = $this->fopen($path1 . $postFix1, 'r');
 						$target = $this->fopen($path2 . $postFix2, 'w');
 						list($count, $result) = \OC_Helper::streamCopy($source, $target);
+						fclose($source);
+						fclose($target);
 					}
 				}
 				if ($this->shouldEmitHooks() && $result !== false) {