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