-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bjoern Schiessle
committed
Jan 15, 2015
1 parent
9b74219
commit 5c7b6be
Showing
6 changed files
with
104 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/** | ||
* ownCloud | ||
* | ||
* @copyright (C) 2015 ownCloud, Inc. | ||
* | ||
* @author Bjoern Schiessle <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace OCA\Files_Trashbin; | ||
|
||
use OC\Files\Storage\Wrapper\Wrapper; | ||
|
||
class Storage extends Wrapper { | ||
|
||
private $mountPoint; | ||
// remember already deleted files to avoid infinite loop if the trash bin | ||
// move files across storages | ||
private $deletedFiles = array(); | ||
|
||
function __construct($parameters) { | ||
$this->mountPoint = $parameters['mountPoint']; | ||
parent::__construct($parameters); | ||
} | ||
|
||
public function unlink($path) { | ||
$normalized = \OC\Files\Filesystem::normalizePath($this->mountPoint . '/' . $path); | ||
$result = true; | ||
if (!isset($this->deletedFiles[$normalized])) { | ||
$this->deletedFiles[$normalized] = $normalized; | ||
$parts = explode('/', $normalized); | ||
if (count($parts) > 3 && $parts[2] === 'files') { | ||
$filesPath = implode('/', array_slice($parts, 3)); | ||
$result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath); | ||
} else { | ||
$result = $this->storage->unlink($path); | ||
} | ||
unset($this->deletedFiles[$normalized]); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Setup the storate wrapper callback | ||
*/ | ||
public static function setupStorage() { | ||
// Set up flock | ||
\OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) { | ||
return new \OCA\Files_Trashbin\Storage(array('storage' => $storage, 'mountPoint' => $mountPoint)); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters