зеркало из https://github.com/nextcloud/server.git
Merge pull request #19500 from owncloud/fix_trash_with_encryption2
[trashbin] fix broken versions on restore
This commit is contained in:
Коммит
f9093688cc
|
@ -142,6 +142,13 @@ class Storage extends Wrapper {
|
||||||
) {
|
) {
|
||||||
return call_user_func_array([$this->storage, $method], [$path]);
|
return call_user_func_array([$this->storage, $method], [$path]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check permissions before we continue, this is especially important for
|
||||||
|
// shared files
|
||||||
|
if (!$this->isDeletable($path)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
|
$normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
|
||||||
$result = true;
|
$result = true;
|
||||||
if (!isset($this->deletedFiles[$normalized])) {
|
if (!isset($this->deletedFiles[$normalized])) {
|
||||||
|
|
|
@ -136,27 +136,28 @@ class Trashbin {
|
||||||
*
|
*
|
||||||
* @param string $sourcePath
|
* @param string $sourcePath
|
||||||
* @param string $owner
|
* @param string $owner
|
||||||
* @param string $ownerPath
|
* @param $targetPath
|
||||||
|
* @param $user
|
||||||
* @param integer $timestamp
|
* @param integer $timestamp
|
||||||
*/
|
*/
|
||||||
private static function copyFilesToOwner($sourcePath, $owner, $ownerPath, $timestamp) {
|
private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user, $timestamp) {
|
||||||
self::setUpTrash($owner);
|
self::setUpTrash($owner);
|
||||||
|
|
||||||
$ownerFilename = basename($ownerPath);
|
$targetFilename = basename($targetPath);
|
||||||
$ownerLocation = dirname($ownerPath);
|
$targetLocation = dirname($targetPath);
|
||||||
|
|
||||||
$sourceFilename = basename($sourcePath);
|
$sourceFilename = basename($sourcePath);
|
||||||
|
|
||||||
$view = new \OC\Files\View('/');
|
$view = new \OC\Files\View('/');
|
||||||
|
|
||||||
$source = \OCP\User::getUser() . '/files_trashbin/files/' . $sourceFilename . '.d' . $timestamp;
|
$target = $user . '/files_trashbin/files/' . $targetFilename . '.d' . $timestamp;
|
||||||
$target = $owner . '/files_trashbin/files/' . $ownerFilename . '.d' . $timestamp;
|
$source = $owner . '/files_trashbin/files/' . $sourceFilename . '.d' . $timestamp;
|
||||||
self::copy_recursive($source, $target, $view);
|
self::copy_recursive($source, $target, $view);
|
||||||
|
|
||||||
|
|
||||||
if ($view->file_exists($target)) {
|
if ($view->file_exists($target)) {
|
||||||
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
|
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
|
||||||
$result = $query->execute(array($ownerFilename, $timestamp, $ownerLocation, $owner));
|
$result = $query->execute(array($targetFilename, $timestamp, $targetLocation, $user));
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
\OCP\Util::writeLog('files_trashbin', 'trash bin database couldn\'t be updated for the files owner', \OCP\Util::ERROR);
|
\OCP\Util::writeLog('files_trashbin', 'trash bin database couldn\'t be updated for the files owner', \OCP\Util::ERROR);
|
||||||
}
|
}
|
||||||
|
@ -168,6 +169,7 @@ class Trashbin {
|
||||||
* move file to the trash bin
|
* move file to the trash bin
|
||||||
*
|
*
|
||||||
* @param string $file_path path to the deleted file/directory relative to the files root directory
|
* @param string $file_path path to the deleted file/directory relative to the files root directory
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function move2trash($file_path) {
|
public static function move2trash($file_path) {
|
||||||
// get the user for which the filesystem is setup
|
// get the user for which the filesystem is setup
|
||||||
|
@ -176,9 +178,9 @@ class Trashbin {
|
||||||
$size = 0;
|
$size = 0;
|
||||||
list($owner, $ownerPath) = self::getUidAndFilename($file_path);
|
list($owner, $ownerPath) = self::getUidAndFilename($file_path);
|
||||||
|
|
||||||
$view = new \OC\Files\View('/' . $user);
|
$ownerView = new \OC\Files\View('/' . $owner);
|
||||||
// file has been deleted in between
|
// file has been deleted in between
|
||||||
if (!$view->file_exists('/files/' . $file_path)) {
|
if (!$ownerView->file_exists('/files/' . $ownerPath)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +190,7 @@ class Trashbin {
|
||||||
self::setUpTrash($owner);
|
self::setUpTrash($owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
$path_parts = pathinfo($file_path);
|
$path_parts = pathinfo($ownerPath);
|
||||||
|
|
||||||
$filename = $path_parts['basename'];
|
$filename = $path_parts['basename'];
|
||||||
$location = $path_parts['dirname'];
|
$location = $path_parts['dirname'];
|
||||||
|
@ -200,9 +202,9 @@ class Trashbin {
|
||||||
$trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp;
|
$trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp;
|
||||||
|
|
||||||
/** @var \OC\Files\Storage\Storage $trashStorage */
|
/** @var \OC\Files\Storage\Storage $trashStorage */
|
||||||
list($trashStorage, $trashInternalPath) = $view->resolvePath($trashPath);
|
list($trashStorage, $trashInternalPath) = $ownerView->resolvePath($trashPath);
|
||||||
/** @var \OC\Files\Storage\Storage $sourceStorage */
|
/** @var \OC\Files\Storage\Storage $sourceStorage */
|
||||||
list($sourceStorage, $sourceInternalPath) = $view->resolvePath('/files/' . $file_path);
|
list($sourceStorage, $sourceInternalPath) = $ownerView->resolvePath('/files/' . $ownerPath);
|
||||||
try {
|
try {
|
||||||
$sizeOfAddedFiles = $sourceStorage->filesize($sourceInternalPath);
|
$sizeOfAddedFiles = $sourceStorage->filesize($sourceInternalPath);
|
||||||
if ($trashStorage->file_exists($trashInternalPath)) {
|
if ($trashStorage->file_exists($trashInternalPath)) {
|
||||||
|
@ -222,23 +224,23 @@ class Trashbin {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$view->getUpdater()->rename('/files/' . $file_path, $trashPath);
|
$ownerView->getUpdater()->rename('/files/' . $ownerPath, $trashPath);
|
||||||
|
|
||||||
if ($sizeOfAddedFiles !== false) {
|
if ($sizeOfAddedFiles !== false) {
|
||||||
$size = $sizeOfAddedFiles;
|
$size = $sizeOfAddedFiles;
|
||||||
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
|
$query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
|
||||||
$result = $query->execute(array($filename, $timestamp, $location, $user));
|
$result = $query->execute(array($filename, $timestamp, $location, $owner));
|
||||||
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' => \OC\Files\Filesystem::normalizePath($file_path),
|
||||||
'trashPath' => \OC\Files\Filesystem::normalizePath($filename . '.d' . $timestamp)));
|
'trashPath' => \OC\Files\Filesystem::normalizePath($filename . '.d' . $timestamp)));
|
||||||
|
|
||||||
$size += self::retainVersions($file_path, $filename, $owner, $ownerPath, $timestamp);
|
$size += self::retainVersions($filename, $owner, $ownerPath, $timestamp);
|
||||||
|
|
||||||
// if owner !== user we need to also add a copy to the owners trash
|
// if owner !== user we need to also add a copy to the owners trash
|
||||||
if ($user !== $owner) {
|
if ($user !== $owner) {
|
||||||
self::copyFilesToOwner($file_path, $owner, $ownerPath, $timestamp);
|
self::copyFilesToUser($ownerPath, $owner, $file_path, $user, $timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +260,6 @@ class Trashbin {
|
||||||
/**
|
/**
|
||||||
* Move file versions to trash so that they can be restored later
|
* Move file versions to trash so that they can be restored later
|
||||||
*
|
*
|
||||||
* @param string $file_path path to original file
|
|
||||||
* @param string $filename of deleted file
|
* @param string $filename of deleted file
|
||||||
* @param string $owner owner user id
|
* @param string $owner owner user id
|
||||||
* @param string $ownerPath path relative to the owner's home storage
|
* @param string $ownerPath path relative to the owner's home storage
|
||||||
|
@ -266,7 +267,7 @@ class Trashbin {
|
||||||
*
|
*
|
||||||
* @return int size of stored versions
|
* @return int size of stored versions
|
||||||
*/
|
*/
|
||||||
private static function retainVersions($file_path, $filename, $owner, $ownerPath, $timestamp) {
|
private static function retainVersions($filename, $owner, $ownerPath, $timestamp) {
|
||||||
$size = 0;
|
$size = 0;
|
||||||
if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) {
|
if (\OCP\App::isEnabled('files_versions') && !empty($ownerPath)) {
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче