Fix bogus deletion on copy + unlink through rename
Cross-storage rename would cause copy + unlink. That unlink operation must not trigger the trashbin.
This commit is contained in:
parent
a1cc9eea56
commit
02b9bad81b
|
@ -33,12 +33,43 @@ class Storage extends Wrapper {
|
||||||
// move files across storages
|
// move files across storages
|
||||||
private $deletedFiles = array();
|
private $deletedFiles = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable trash logic
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private static $disableTrash = false;
|
||||||
|
|
||||||
function __construct($parameters) {
|
function __construct($parameters) {
|
||||||
$this->mountPoint = $parameters['mountPoint'];
|
$this->mountPoint = $parameters['mountPoint'];
|
||||||
parent::__construct($parameters);
|
parent::__construct($parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public static function preRenameHook($params) {
|
||||||
|
// in cross-storage cases, a rename is a copy + unlink,
|
||||||
|
// that last unlink must not go to trash
|
||||||
|
self::$disableTrash = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public static function postRenameHook($params) {
|
||||||
|
self::$disableTrash = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the given file by moving it into the trashbin.
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
*/
|
||||||
public function unlink($path) {
|
public function unlink($path) {
|
||||||
|
if (self::$disableTrash) {
|
||||||
|
return $this->storage->unlink($path);
|
||||||
|
}
|
||||||
$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])) {
|
||||||
|
|
|
@ -928,6 +928,9 @@ class Trashbin {
|
||||||
\OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook');
|
\OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook');
|
||||||
//Listen to post write hook
|
//Listen to post write hook
|
||||||
\OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook');
|
\OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook');
|
||||||
|
// pre and post-rename, disable trash logic for the copy+unlink case
|
||||||
|
\OCP\Util::connectHook('OC_Filesystem', 'rename', 'OCA\Files_Trashbin\Storage', 'preRenameHook');
|
||||||
|
\OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Files_Trashbin\Storage', 'postRenameHook');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,6 +37,9 @@ class Storage extends \Test\TestCase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
\OC_Hook::clear();
|
||||||
|
\OCA\Files_Trashbin\Trashbin::registerHooks();
|
||||||
|
|
||||||
$this->user = $this->getUniqueId('user');
|
$this->user = $this->getUniqueId('user');
|
||||||
\OC::$server->getUserManager()->createUser($this->user, $this->user);
|
\OC::$server->getUserManager()->createUser($this->user, $this->user);
|
||||||
|
|
||||||
|
@ -58,6 +61,7 @@ class Storage extends \Test\TestCase {
|
||||||
\OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
|
\OC\Files\Filesystem::mount($this->originalStorage, array(), '/');
|
||||||
$this->logout();
|
$this->logout();
|
||||||
\OC_User::deleteUser($this->user);
|
\OC_User::deleteUser($this->user);
|
||||||
|
\OC_Hook::clear();
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue