1010
1111use OC \Core \Command \Info \FileUtils ;
1212use OCA \Files_Sharing \SharedStorage ;
13+ use OCA \Files_Trashbin \Trash \ITrashManager ;
1314use OCP \Files \Folder ;
1415use Symfony \Component \Console \Command \Command ;
1516use Symfony \Component \Console \Helper \QuestionHelper ;
2122
2223class 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