diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php
index 62d70d7356a5199c41e7ee5c2fc64f1f34397e6f..3b386b0abd882b66b5e1eeff4762931ed787cc36 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -43,6 +43,7 @@ use OC\Files\View;
 use OCA\Files_Trashbin\AppInfo\Application;
 use OCA\Files_Trashbin\Command\Expire;
 use OCP\Files\NotFoundException;
+use OCP\User;
 
 class Trashbin {
 
@@ -71,12 +72,33 @@ class Trashbin {
 	}
 
 	/**
+	 * get the UID of the owner of the file and the path to the file relative to
+	 * owners files folder
+	 *
 	 * @param string $filename
 	 * @return array
 	 * @throws \OC\User\NoUserException
 	 */
 	public static function getUidAndFilename($filename) {
-		return Filesystem::getView()->getUidAndFilename($filename);
+		$uid = Filesystem::getOwner($filename);
+		$userManager = \OC::$server->getUserManager();
+		// if the user with the UID doesn't exists, e.g. because the UID points
+		// to a remote user with a federated cloud ID we use the current logged-in
+		// user. We need a valid local user to move the file to the right trash bin
+		if (!$userManager->userExists($uid)) {
+			$uid = User::getUser();
+		}
+		Filesystem::initMountPoints($uid);
+		if ($uid != User::getUser()) {
+			$info = Filesystem::getFileInfo($filename);
+			$ownerView = new View('/' . $uid . '/files');
+			try {
+				$filename = $ownerView->getPath($info['fileid']);
+			} catch (NotFoundException $e) {
+				$filename = null;
+			}
+		}
+		return [$uid, $filename];
 	}
 
 	/**
@@ -120,7 +142,7 @@ class Trashbin {
 	}
 
 	private static function setUpTrash($user) {
-		$view = new \OC\Files\View('/' . $user);
+		$view = new View('/' . $user);
 		if (!$view->is_dir('files_trashbin')) {
 			$view->mkdir('files_trashbin');
 		}
@@ -153,7 +175,7 @@ class Trashbin {
 
 		$sourceFilename = basename($sourcePath);
 
-		$view = new \OC\Files\View('/');
+		$view = new View('/');
 
 		$target = $user . '/files_trashbin/files/' . $targetFilename . '.d' . $timestamp;
 		$source = $owner . '/files_trashbin/files/' . $sourceFilename . '.d' . $timestamp;
@@ -182,7 +204,7 @@ class Trashbin {
 		list(, $user) = explode('/', $root);
 		list($owner, $ownerPath) = self::getUidAndFilename($file_path);
 
-		$ownerView = new \OC\Files\View('/' . $owner);
+		$ownerView = new View('/' . $owner);
 		// file has been deleted in between
 		if (!$ownerView->file_exists('/files/' . $ownerPath)) {
 			return true;
@@ -234,8 +256,8 @@ class Trashbin {
 			if (!$result) {
 				\OCP\Util::writeLog('files_trashbin', 'trash bin database couldn\'t be updated', \OCP\Util::ERROR);
 			}
-			\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', array('filePath' => \OC\Files\Filesystem::normalizePath($file_path),
-				'trashPath' => \OC\Files\Filesystem::normalizePath($filename . '.d' . $timestamp)));
+			\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', array('filePath' => Filesystem::normalizePath($file_path),
+				'trashPath' => Filesystem::normalizePath($filename . '.d' . $timestamp)));
 
 			self::retainVersions($filename, $owner, $ownerPath, $timestamp);
 
@@ -266,8 +288,8 @@ class Trashbin {
 	private static function retainVersions($filename, $owner, $ownerPath, $timestamp) {
 		if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) {
 
-			$user = \OCP\User::getUser();
-			$rootView = new \OC\Files\View('/');
+			$user = User::getUser();
+			$rootView = new View('/');
 
 			if ($rootView->is_dir($owner . '/files_versions/' . $ownerPath)) {
 				if ($owner !== $user) {
@@ -341,8 +363,8 @@ class Trashbin {
 	 * @return bool true on success, false otherwise
 	 */
 	public static function restore($file, $filename, $timestamp) {
-		$user = \OCP\User::getUser();
-		$view = new \OC\Files\View('/' . $user);
+		$user = User::getUser();
+		$view = new View('/' . $user);
 
 		$location = '';
 		if ($timestamp) {
@@ -363,8 +385,8 @@ class Trashbin {
 		// we need a  extension in case a file/dir with the same name already exists
 		$uniqueFilename = self::getUniqueFilename($location, $filename, $view);
 
-		$source = \OC\Files\Filesystem::normalizePath('files_trashbin/files/' . $file);
-		$target = \OC\Files\Filesystem::normalizePath('files/' . $location . '/' . $uniqueFilename);
+		$source = Filesystem::normalizePath('files_trashbin/files/' . $file);
+		$target = Filesystem::normalizePath('files/' . $location . '/' . $uniqueFilename);
 		if (!$view->file_exists($source)) {
 			return false;
 		}
@@ -379,8 +401,8 @@ class Trashbin {
 			$view->chroot('/' . $user . '/files');
 			$view->touch('/' . $location . '/' . $uniqueFilename, $mtime);
 			$view->chroot($fakeRoot);
-			\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', array('filePath' => \OC\Files\Filesystem::normalizePath('/' . $location . '/' . $uniqueFilename),
-				'trashPath' => \OC\Files\Filesystem::normalizePath($file)));
+			\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', array('filePath' => Filesystem::normalizePath('/' . $location . '/' . $uniqueFilename),
+				'trashPath' => Filesystem::normalizePath($file)));
 
 			self::restoreVersions($view, $file, $filename, $uniqueFilename, $location, $timestamp);
 
@@ -398,7 +420,7 @@ class Trashbin {
 	/**
 	 * restore versions from trash bin
 	 *
-	 * @param \OC\Files\View $view file view
+	 * @param View $view file view
 	 * @param string $file complete path to file
 	 * @param string $filename name of file once it was deleted
 	 * @param string $uniqueFilename new file name to restore the file without overwriting existing files
@@ -406,14 +428,14 @@ class Trashbin {
 	 * @param int $timestamp deletion time
 	 * @return false|null
 	 */
-	private static function restoreVersions(\OC\Files\View $view, $file, $filename, $uniqueFilename, $location, $timestamp) {
+	private static function restoreVersions(View $view, $file, $filename, $uniqueFilename, $location, $timestamp) {
 
 		if (\OCP\App::isEnabled('files_versions')) {
 
-			$user = \OCP\User::getUser();
-			$rootView = new \OC\Files\View('/');
+			$user = User::getUser();
+			$rootView = new View('/');
 
-			$target = \OC\Files\Filesystem::normalizePath('/' . $location . '/' . $uniqueFilename);
+			$target = Filesystem::normalizePath('/' . $location . '/' . $uniqueFilename);
 
 			list($owner, $ownerPath) = self::getUidAndFilename($target);
 
@@ -429,7 +451,7 @@ class Trashbin {
 			}
 
 			if ($view->is_dir('/files_trashbin/versions/' . $file)) {
-				$rootView->rename(\OC\Files\Filesystem::normalizePath($user . '/files_trashbin/versions/' . $file), \OC\Files\Filesystem::normalizePath($owner . '/files_versions/' . $ownerPath));
+				$rootView->rename(Filesystem::normalizePath($user . '/files_trashbin/versions/' . $file), Filesystem::normalizePath($owner . '/files_versions/' . $ownerPath));
 			} else if ($versions = self::getVersionsFromTrash($versionedFile, $timestamp, $user)) {
 				foreach ($versions as $v) {
 					if ($timestamp) {
@@ -446,8 +468,8 @@ class Trashbin {
 	 * delete all files from the trash
 	 */
 	public static function deleteAll() {
-		$user = \OCP\User::getUser();
-		$view = new \OC\Files\View('/' . $user);
+		$user = User::getUser();
+		$view = new View('/' . $user);
 		$view->deleteAll('files_trashbin');
 		$query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=?');
 		$query->execute(array($user));
@@ -467,7 +489,7 @@ class Trashbin {
 	 * @return int size of deleted files
 	 */
 	public static function delete($filename, $user, $timestamp = null) {
-		$view = new \OC\Files\View('/' . $user);
+		$view = new View('/' . $user);
 		$size = 0;
 
 		if ($timestamp) {
@@ -481,7 +503,7 @@ class Trashbin {
 		$size += self::deleteVersions($view, $file, $filename, $timestamp, $user);
 
 		if ($view->is_dir('/files_trashbin/files/' . $file)) {
-			$size += self::calculateSize(new \OC\Files\View('/' . $user . '/files_trashbin/files/' . $file));
+			$size += self::calculateSize(new View('/' . $user . '/files_trashbin/files/' . $file));
 		} else {
 			$size += $view->filesize('/files_trashbin/files/' . $file);
 		}
@@ -493,18 +515,18 @@ class Trashbin {
 	}
 
 	/**
-	 * @param \OC\Files\View $view
+	 * @param View $view
 	 * @param string $file
 	 * @param string $filename
 	 * @param integer|null $timestamp
 	 * @param string $user
 	 * @return int
 	 */
-	private static function deleteVersions(\OC\Files\View $view, $file, $filename, $timestamp, $user) {
+	private static function deleteVersions(View $view, $file, $filename, $timestamp, $user) {
 		$size = 0;
 		if (\OCP\App::isEnabled('files_versions')) {
 			if ($view->is_dir('files_trashbin/versions/' . $file)) {
-				$size += self::calculateSize(new \OC\Files\view('/' . $user . '/files_trashbin/versions/' . $file));
+				$size += self::calculateSize(new View('/' . $user . '/files_trashbin/versions/' . $file));
 				$view->unlink('files_trashbin/versions/' . $file);
 			} else if ($versions = self::getVersionsFromTrash($filename, $timestamp, $user)) {
 				foreach ($versions as $v) {
@@ -529,8 +551,8 @@ class Trashbin {
 	 * @return bool true if file exists, otherwise false
 	 */
 	public static function file_exists($filename, $timestamp = null) {
-		$user = \OCP\User::getUser();
-		$view = new \OC\Files\View('/' . $user);
+		$user = User::getUser();
+		$view = new View('/' . $user);
 
 		if ($timestamp) {
 			$filename = $filename . '.d' . $timestamp;
@@ -538,7 +560,7 @@ class Trashbin {
 			$filename = $filename;
 		}
 
-		$target = \OC\Files\Filesystem::normalizePath('files_trashbin/files/' . $filename);
+		$target = Filesystem::normalizePath('files_trashbin/files/' . $filename);
 		return $view->file_exists($target);
 	}
 
@@ -568,7 +590,7 @@ class Trashbin {
 		}
 		$quota = $userObject->getQuota();
 		if ($quota === null || $quota === 'none') {
-			$quota = \OC\Files\Filesystem::free_space('/');
+			$quota = Filesystem::free_space('/');
 			$softQuota = false;
 			// inf or unknown free space
 			if ($quota < 0) {
@@ -710,11 +732,11 @@ class Trashbin {
 	 *
 	 * @param string $source source path, relative to the users files directory
 	 * @param string $destination destination path relative to the users root directoy
-	 * @param \OC\Files\View $view file view for the users root directory
+	 * @param View $view file view for the users root directory
 	 * @return int
 	 * @throws Exceptions\CopyRecursiveException
 	 */
-	private static function copy_recursive($source, $destination, \OC\Files\View $view) {
+	private static function copy_recursive($source, $destination, View $view) {
 		$size = 0;
 		if ($view->is_dir($source)) {
 			$view->mkdir($destination);
@@ -751,7 +773,7 @@ class Trashbin {
 	 * @return array
 	 */
 	private static function getVersionsFromTrash($filename, $timestamp, $user) {
-		$view = new \OC\Files\View('/' . $user . '/files_trashbin/versions');
+		$view = new View('/' . $user . '/files_trashbin/versions');
 		$versions = array();
 
 		//force rescan of versions, local storage may not have updated the cache
@@ -789,10 +811,10 @@ class Trashbin {
 	 *
 	 * @param string $location where the file should be restored
 	 * @param string $filename name of the file
-	 * @param \OC\Files\View $view filesystem view relative to users root directory
+	 * @param View $view filesystem view relative to users root directory
 	 * @return string with unique extension
 	 */
-	private static function getUniqueFilename($location, $filename, \OC\Files\View $view) {
+	private static function getUniqueFilename($location, $filename, View $view) {
 		$ext = pathinfo($filename, PATHINFO_EXTENSION);
 		$name = pathinfo($filename, PATHINFO_FILENAME);
 		$l = \OC::$server->getL10N('files_trashbin');
@@ -821,7 +843,7 @@ class Trashbin {
 	/**
 	 * get the size from a given root folder
 	 *
-	 * @param \OC\Files\View $view file view on the root folder
+	 * @param View $view file view on the root folder
 	 * @return integer size of the folder
 	 */
 	private static function calculateSize($view) {
@@ -856,7 +878,7 @@ class Trashbin {
 	 * @return integer trash bin size
 	 */
 	private static function getTrashbinSize($user) {
-		$view = new \OC\Files\View('/' . $user);
+		$view = new View('/' . $user);
 		$fileInfo = $view->getFileInfo('/files_trashbin');
 		return isset($fileInfo['size']) ? $fileInfo['size'] : 0;
 	}
@@ -885,10 +907,10 @@ class Trashbin {
 	 */
 	public static function isEmpty($user) {
 
-		$view = new \OC\Files\View('/' . $user . '/files_trashbin');
+		$view = new View('/' . $user . '/files_trashbin');
 		if ($view->is_dir('/files') && $dh = $view->opendir('/files')) {
 			while ($file = readdir($dh)) {
-				if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
+				if (!Filesystem::isIgnoredDir($file)) {
 					return false;
 				}
 			}
diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php
index d5e21959698030dc6ceb651fffabbf3c2673b1a7..da736c868fc1c00b1682f49b66f747ae8bada785 100644
--- a/apps/files_versions/lib/storage.php
+++ b/apps/files_versions/lib/storage.php
@@ -42,9 +42,11 @@
 namespace OCA\Files_Versions;
 
 use OC\Files\Filesystem;
+use OC\Files\View;
 use OCA\Files_Versions\AppInfo\Application;
 use OCA\Files_Versions\Command\Expire;
 use OCP\Lock\ILockingProvider;
+use OCP\User;
 
 class Storage {
 
@@ -80,12 +82,33 @@ class Storage {
 	private static $application;
 
 	/**
+	 * get the UID of the owner of the file and the path to the file relative to
+	 * owners files folder
+	 *
 	 * @param string $filename
 	 * @return array
 	 * @throws \OC\User\NoUserException
 	 */
 	public static function getUidAndFilename($filename) {
-		return Filesystem::getView()->getUidAndFilename($filename);
+		$uid = Filesystem::getOwner($filename);
+		$userManager = \OC::$server->getUserManager();
+		// if the user with the UID doesn't exists, e.g. because the UID points
+		// to a remote user with a federated cloud ID we use the current logged-in
+		// user. We need a valid local user to create the versions
+		if (!$userManager->userExists($uid)) {
+			$uid = User::getUser();
+		}
+		Filesystem::initMountPoints($uid);
+		if ( $uid != User::getUser() ) {
+			$info = Filesystem::getFileInfo($filename);
+			$ownerView = new View('/'.$uid.'/files');
+			try {
+				$filename = $ownerView->getPath($info['fileid']);
+			} catch (NotFoundException $e) {
+				$filename = null;
+			}
+		}
+		return [$uid, $filename];
 	}
 
 	/**
@@ -123,7 +146,7 @@ class Storage {
 	 * @return int versions size
 	 */
 	private static function getVersionsSize($user) {
-		$view = new \OC\Files\View('/' . $user);
+		$view = new View('/' . $user);
 		$fileInfo = $view->getFileInfo('/files_versions');
 		return isset($fileInfo['size']) ? $fileInfo['size'] : 0;
 	}
@@ -148,8 +171,8 @@ class Storage {
 
 			list($uid, $filename) = self::getUidAndFilename($filename);
 
-			$files_view = new \OC\Files\View('/'.$uid .'/files');
-			$users_view = new \OC\Files\View('/'.$uid);
+			$files_view = new View('/'.$uid .'/files');
+			$users_view = new View('/'.$uid);
 
 			// no use making versions for empty files
 			if ($files_view->filesize($filename) === 0) {
@@ -189,7 +212,7 @@ class Storage {
 	/**
 	 * delete the version from the storage and cache
 	 *
-	 * @param \OC\Files\View $view
+	 * @param View $view
 	 * @param string $path
 	 */
 	protected static function deleteVersion($view, $path) {
@@ -212,9 +235,9 @@ class Storage {
 		$uid = $deletedFile['uid'];
 		$filename = $deletedFile['filename'];
 
-		if (!\OC\Files\Filesystem::file_exists($path)) {
+		if (!Filesystem::file_exists($path)) {
 
-			$view = new \OC\Files\View('/' . $uid . '/files_versions');
+			$view = new View('/' . $uid . '/files_versions');
 
 			$versions = self::getVersions($uid, $filename);
 			if (!empty($versions)) {
@@ -252,14 +275,14 @@ class Storage {
 		$sourcePath = ltrim($sourcePath, '/');
 		$targetPath = ltrim($targetPath, '/');
 
-		$rootView = new \OC\Files\View('');
+		$rootView = new View('');
 
 		// did we move a directory ?
 		if ($rootView->is_dir('/' . $targetOwner . '/files/' . $targetPath)) {
 			// does the directory exists for versions too ?
 			if ($rootView->is_dir('/' . $sourceOwner . '/files_versions/' . $sourcePath)) {
 				// create missing dirs if necessary
-				self::createMissingDirectories($targetPath, new \OC\Files\View('/'. $targetOwner));
+				self::createMissingDirectories($targetPath, new View('/'. $targetOwner));
 
 				// move the directory containing the versions
 				$rootView->$operation(
@@ -269,7 +292,7 @@ class Storage {
 			}
 		} else if ($versions = Storage::getVersions($sourceOwner, '/' . $sourcePath)) {
 			// create missing dirs if necessary
-			self::createMissingDirectories($targetPath, new \OC\Files\View('/'. $targetOwner));
+			self::createMissingDirectories($targetPath, new View('/'. $targetOwner));
 
 			foreach ($versions as $v) {
 				// move each version one by one to the target directory
@@ -299,8 +322,8 @@ class Storage {
 			// add expected leading slash
 			$file = '/' . ltrim($file, '/');
 			list($uid, $filename) = self::getUidAndFilename($file);
-			$users_view = new \OC\Files\View('/'.$uid);
-			$files_view = new \OC\Files\View('/'.\OCP\User::getUser().'/files');
+			$users_view = new View('/'.$uid);
+			$files_view = new View('/'. User::getUser().'/files');
 			$versionCreated = false;
 
 			//first create a new version
@@ -332,7 +355,7 @@ class Storage {
 	/**
 	 * Stream copy file contents from $path1 to $path2
 	 *
-	 * @param \OC\Files\View $view view to use for copying
+	 * @param View $view view to use for copying
 	 * @param string $path1 source file to copy
 	 * @param string $path2 target file
 	 *
@@ -381,12 +404,12 @@ class Storage {
 			return $versions;
 		}
 		// fetch for old versions
-		$view = new \OC\Files\View('/' . $uid . '/');
+		$view = new View('/' . $uid . '/');
 
 		$pathinfo = pathinfo($filename);
 		$versionedFile = $pathinfo['basename'];
 
-		$dir = \OC\Files\Filesystem::normalizePath(self::VERSIONS_ROOT . '/' . $pathinfo['dirname']);
+		$dir = Filesystem::normalizePath(self::VERSIONS_ROOT . '/' . $pathinfo['dirname']);
 
 		$dirContent = false;
 		if ($view->is_dir($dir)) {
@@ -399,7 +422,7 @@ class Storage {
 
 		if (is_resource($dirContent)) {
 			while (($entryName = readdir($dirContent)) !== false) {
-				if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
+				if (!Filesystem::isIgnoredDir($entryName)) {
 					$pathparts = pathinfo($entryName);
 					$filename = $pathparts['filename'];
 					if ($filename === $versionedFile) {
@@ -414,7 +437,7 @@ class Storage {
 						} else {
 							$versions[$key]['preview'] = \OCP\Util::linkToRoute('core_ajax_versions_preview', array('file' => $userFullPath, 'version' => $timestamp));
 						}
-						$versions[$key]['path'] = \OC\Files\Filesystem::normalizePath($pathinfo['dirname'] . '/' . $filename);
+						$versions[$key]['path'] = Filesystem::normalizePath($pathinfo['dirname'] . '/' . $filename);
 						$versions[$key]['name'] = $versionedFile;
 						$versions[$key]['size'] = $view->filesize($dir . '/' . $entryName);
 					}
@@ -451,7 +474,7 @@ class Storage {
 			}
 		}
 
-		$view = new \OC\Files\View('/' . $uid . '/files_versions');
+		$view = new View('/' . $uid . '/files_versions');
 		if (!empty($toDelete)) {
 			foreach ($toDelete as $version) {
 				\OC_Hook::emit('\OCP\Versions', 'preDelete', array('path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_RETENTION_CONSTRAINT));
@@ -494,7 +517,7 @@ class Storage {
 	 * @return array with contains two arrays 'all' which contains all versions sorted by age and 'by_file' which contains all versions sorted by filename
 	 */
 	private static function getAllVersions($uid) {
-		$view = new \OC\Files\View('/' . $uid . '/');
+		$view = new View('/' . $uid . '/');
 		$dirs = array(self::VERSIONS_ROOT);
 		$versions = array();
 
@@ -655,14 +678,14 @@ class Storage {
 				// file maybe renamed or deleted
 				return false;
 			}
-			$versionsFileview = new \OC\Files\View('/'.$uid.'/files_versions');
+			$versionsFileview = new View('/'.$uid.'/files_versions');
 
 			// get available disk space for user
 			$user = \OC::$server->getUserManager()->get($uid);
 			$softQuota = true;
 			$quota = $user->getQuota();
 			if ( $quota === null || $quota === 'none' ) {
-				$quota = \OC\Files\Filesystem::free_space('/');
+				$quota = Filesystem::free_space('/');
 				$softQuota = false;
 			} else {
 				$quota = \OCP\Util::computerFileSize($quota);
@@ -675,7 +698,7 @@ class Storage {
 			// subtract size of files and current versions size from quota
 			if ($quota >= 0) {
 				if ($softQuota) {
-					$files_view = new \OC\Files\View('/' . $uid . '/files');
+					$files_view = new View('/' . $uid . '/files');
 					$rootInfo = $files_view->getFileInfo('/', false);
 					$free = $quota - $rootInfo['size']; // remaining free space for user
 					if ($free > 0) {
@@ -752,10 +775,10 @@ class Storage {
 	 *
 	 * @param string $filename $path to a file, relative to the user's
 	 * "files" folder
-	 * @param \OC\Files\View $view view on data/user/
+	 * @param View $view view on data/user/
 	 */
 	private static function createMissingDirectories($filename, $view) {
-		$dirname = \OC\Files\Filesystem::normalizePath(dirname($filename));
+		$dirname = Filesystem::normalizePath(dirname($filename));
 		$dirParts = explode('/', $dirname);
 		$dir = "/files_versions";
 		foreach ($dirParts as $part) {