Skip to content

Commit b850ced

Browse files
committed
feat: add option to skip trashbin in files:delete
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 25268f4 commit b850ced

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

apps/files/lib/Command/Delete.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use OC\Core\Command\Info\FileUtils;
1212
use OCA\Files_Sharing\SharedStorage;
13+
use OCA\Files_Trashbin\Trash\ITrashManager;
1314
use OCP\Files\Folder;
1415
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Helper\QuestionHelper;
@@ -21,7 +22,8 @@
2122

2223
class Delete extends Command {
2324
public function __construct(
24-
private FileUtils $fileUtils,
25+
private readonly FileUtils $fileUtils,
26+
private readonly ITrashManager $trashManager,
2527
) {
2628
parent::__construct();
2729
}
@@ -32,14 +34,16 @@ protected function configure(): void {
3234
->setName('files:delete')
3335
->setDescription('Delete a file or folder')
3436
->addArgument('file', InputArgument::REQUIRED, 'File id or path')
35-
->addOption('force', 'f', InputOption::VALUE_NONE, "Don't ask for configuration and don't output any warnings");
37+
->addOption('force', 'f', InputOption::VALUE_NONE, "Don't ask for configuration and don't output any warnings")
38+
->addOption('skip-trash', null, InputOption::VALUE_NONE, 'Bypass the trashbin when deleting the file or folder');
3639
}
3740

3841
#[\Override]
3942
public function execute(InputInterface $input, OutputInterface $output): int {
4043
$fileInput = $input->getArgument('file');
4144
$inputIsId = is_numeric($fileInput);
4245
$force = $input->getOption('force');
46+
$skipTrash = $input->getOption('skip-trash');
4347
$node = $this->fileUtils->getNode($fileInput);
4448

4549
if (!$node) {
@@ -90,6 +94,10 @@ public function execute(InputInterface $input, OutputInterface $output): int {
9094

9195
if ($deleteConfirmed) {
9296
if ($node->isDeletable()) {
97+
if ($skipTrash && $this->trashManager) {
98+
$this->trashManager->pauseTrash();
99+
}
100+
93101
$node->delete();
94102
} else {
95103
$output->writeln('<error>File cannot be deleted, insufficient permissions.</error>');

0 commit comments

Comments
 (0)