server icon indicating copy to clipboard operation
server copied to clipboard

Ability to disable trash bin on External Storage (and/or per folder)

Open efelon opened this issue 6 years ago • 10 comments

Is your feature request related to a problem? Please describe. When adding external storage folder (e.g. SMB) they integrate nicely. But when deleting elements out of those folder they will be moved to local trash bin, which can take a very long time depending on the file size, connection, etc. and this may sometimes even not be desired.

Describe the solution you'd like A good general solution would be to disable trash bin manually on a per folder basis. Or in the settings where the user can list folders to be excluded.

Describe alternatives you've considered One alternative would be to outsource the solution specifically to the external storage add-on and provide a similar option only there on a per share basis.

efelon avatar Feb 28 '19 12:02 efelon

Related to #18396

efelon avatar Jan 16 '20 20:01 efelon

I agree with including this enhancement, having files moved across from external storage especially if it's located remotely e.g. SMB or even AWS, is not always desirable, more so if the files are extremely large.

Taomyn avatar Feb 05 '20 12:02 Taomyn

This is very relevant for people who use seedvault for android backups with Nextcloud as a backup target. A ton of random files will be placed in trash on a daily basis, and it would be great if we could exclude the seedvault directory contents from being "recycled", as otherwise I am constantly at risk of running out of space and have to delete the files manually. Standard trash retention policies are not effective for this issue.

I suggest a .notrash or .norecycle file in the directory to recursively disallow moving files to the trash/recycling when they are deleted. In case it is important for implementation, the files I mention are not deleted by the user, but by some automated process.

tnyeanderson avatar Jan 12 '23 02:01 tnyeanderson

Looks like the implementation belongs in the moveToTrash function, but I'm not sure as I'm unfamiliar with the code here.

tnyeanderson avatar Jan 12 '23 02:01 tnyeanderson

How is this even still a thing in a mature cloud storage application? If it hadn't been raised as an issue till recently that would be one thing, but... There are multiple issues and pull requests regarding this same problem, and dozens of relevant search results of forum posts that date back years. Yet there's no timeline for merging the pull request apparently and it's been closed? I mean, certainly not encouraging me to help if that's how community contribution is treated.

The best solution we have right now is 'create a symlink for every user's trash folder.' And that only works if you only have one external device. This is absurd. Per-device trash is a basic feature that any user would expect, and has existed in Linux, Windows, Mac OS, not to mention part of SMB/NFS/etc protocols, for over a decade.

How does it make ANY sense that you'd download a file to local disk storage to put it in a local trash folder instead of just moving the file into a hidden folder of a standard format such as .Trash-$UID or .trash/$username. It blows my mind that that the decision was actively made to make it work this way to begin with. The External Storage extension just straight up shouldn't have been released in this state, which I'd call counter-intuitive at best, and broken at worst.

It's also perfectly normal on most NAS hardware (such as mine) that the primary drive is some puny internal storage device that usually can't handle being filled up with everyone's junk. And when it comes to using the plugin for network or cloud storage, it makes even less sense, now you're pulling large files over the internet all just to "delete" them when you could've simply called a single move/rename command to place it in a trash folder without going cross-device.

Pecacheu avatar Jan 30 '23 14:01 Pecacheu

@Pecacheu Of course I understand your frustration, I am waiting on this feature as well and it is a huge pain point for me.

However, we have to remember that there are 2,300 open issues at the moment, and over 15,000 total issues have been in this repo. The Nextcloud team is rather small and stretched thin (I might say due to the decision to bloat features, but I can't be the one to determine that).

I try to contribute where I can, and I encourage everyone to do the same. You and I can prioritize this very highly, but at the end of the day the Nextcloud team might not, and we have to either be patient and wait for the fix for free, or get our hands dirty and start implementing these things ourselves. Or maybe a bounty would help get some eyes on it.

In the meantime, I'll try to take another look at implementation on this in the coming weeks.

tnyeanderson avatar Jan 30 '23 23:01 tnyeanderson

@tnyeanderson Alright fair point, that is a LOT of issues haha. Perhaps I can take a look and add some logging in that moveToTrash function you pointed out, to see if/what it gets called with when using the External Storage plugin.

As for now, the temporary "hotfix" people have suggested, creating a symlink to redirect where the trash goes, will work for me since I only have one shared external location mounted. Best that all trash is directed to the BIG disk.

Pecacheu avatar Jan 31 '23 00:01 Pecacheu

Any news on this? I get the point that there is an huge amount of issues and most of them may have higher prio than this.

But at least this one and #18396 show, that there is real pain for some users including me. Just flooded my primary disk with trashbin-files from a much larger disk I'm using via external storage. And the deletion progress (which is a copy instead) is also pain, as it takes much more time as I would expect for a deletion.

Maybe @szaimen can take another look at #22632 and #23489 how to implement this at least for external storage?

loeffelpan avatar Mar 26 '23 11:03 loeffelpan

Related recent merge: #38623

joshtrichards avatar Oct 24 '23 21:10 joshtrichards

In recent years I just disabled the "Deleted Files" app. But now that produces errors. What is the best way to disable the trash entirely?

We're using big files. Sadly this concept is conflicting.

labor4 avatar Mar 29 '24 23:03 labor4

There is this PR that attempted to fix this issue some years back https://github.com/nextcloud/server/pull/23489

Unfortunately we can't resurrect it due to the frontend having been migrated to vue and a few other backend-side nitpicks, it would be better to create a PR from scratch.

sorbaugh avatar Oct 07 '24 14:10 sorbaugh

+1 for this feature. This causes a lot of confusion for our users.

deanjarnold avatar Dec 30 '24 00:12 deanjarnold

and when it will be merged? Or how other way can we use this feature? This is awesome feature, and I just can't believe it, that it is being developed now, not earlier, specially it is not very hard to implement.

tomekszy avatar Jan 24 '25 10:01 tomekszy

#14436 is merged but will not solve this issue, though it does provide a mechanism which can be used to bypass the trash bin when a client calls for the delete. However, that would require the client to know whether the trash bin should be bypassed for a given file/dir that is to be deleted, which is fine when an app like Seedvault is going to clean up outdated backup chunks by itself, or if the client prompted the user "would you like to delete this permanently or move to the trash bin" (for example).

Unfortunately, it does not solve this issue specifically. The ability to bypass the trash bin for all of external storage, or even on a per directory basis (like with .notrash discussed above) is still not implemented, nor is an independent trash bin for external storage. And when it is, it will almost definitely need to be done on the server, not from the client, for the reasons described above.

P.S. - it's kind of rude to say things like "this isn't very hard to implement" and imply it should have been done sooner, unless you are willing to open a PR yourself with a solution. See my comment here.

tnyeanderson avatar Jan 25 '25 03:01 tnyeanderson

about P.S. - sorry, you are right. I am developer myself, and I know how difficult things could be, specially those, which looks very simple from the outside.

tomekszy avatar Jan 27 '25 07:01 tomekszy

As we are looking into NFS mounting big media files, I would really look forward to having this as well!

xeruf avatar Apr 30 '25 16:04 xeruf

Same use case here as Pecacheu, tiny main drive with user data on external storage. Ran into unexpected space issues on the main drive the other day and found my way here.

gabechiarelli avatar May 18 '25 19:05 gabechiarelli

In my use case, I have added rclone with SFTP, Google Drive, etc. This is generally a problem when using local paths that have been mounted. It would also be better if an invisible folder were created in the directory where data is moved. Otherwise, deleting data takes forever and also unnecessarily wears out the SSD, reducing its lifespan. Currently, I always have to delete data via SSH. It would be nice if this could be considered, so I could also enable the trash. The same problem exists for file version.

Disable Trashbin for External Storage (Unofficial Patch)

Since there is no official solution yet, here is a small patch based on a closed PR, simplified as a workaround.

Usage

  1. Create a file named patch_no_trashbin.sh and insert the script.
  2. Make it executable: chmod +x patch_no_trashbin.sh Run the script: sudo ./patch_no_trashbin.sh

If multiple PHP versions are installed, you may need to adjust the PHP command in the script (e.g., php8.3 instead of php) to avoid errors.

Enable/Disable “No Trashbin” Globally for All External Storages

sudo -u www-data php /var/www/nextcloud/occ config:app:set files_external default_no_trashbin --value=true   # enable
sudo -u www-data php /var/www/nextcloud/occ config:app:set files_external default_no_trashbin --value=false  # disable

Enable/Disable “No Trashbin” for a Specific External Storage

  1. List all external storages to find the mount ID
sudo -u www-data php /var/www/nextcloud/occ files_external:list
  1. Enable or disable the no_trashbin option for a specific mount
sudo -u www-data php /var/www/nextcloud/occ files_external:option <mount-id> no_trashbin true   # enable
sudo -u www-data php /var/www/nextcloud/occ files_external:option <mount-id> no_trashbin false  # disable

This patch will automatically create the listener, patch Application.php, update the composer autoload files, set the default_no_trashbin config to true, set ownership to www-data, and restart Apache.

Note: Use this at your own risk; it’s a temporary workaround until an official solution exists.

@dassio @sorbaugh I noticed the PR was mainly closed because the Vue frontend was in the way. Wouldn’t it be possible, like I did, to just create a version without the GUI?

Patch Script (click to expand)
#!/bin/bash
set -e

NC_DIR="/var/www/nextcloud"

echo "[INFO] Nextcloud-Verzeichnis: $NC_DIR"

LISTENER_FILE="$NC_DIR/apps/files_external/lib/Listener/MoveToTrashListener.php"

# Create listener
echo "[INFO] Create listener file..."
mkdir -p "$(dirname "$LISTENER_FILE")"
cat > "$LISTENER_FILE" <<'PHP'
<?php

declare(strict_types=1);

namespace OCA\Files_External\Listener;

use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCA\Files_Trashbin\Events\MoveToTrashEvent;

class MoveToTrashListener implements IEventListener {
    public function handle(Event $event): void {
        if (!$event instanceof MoveToTrashEvent) {
            return;
        }

        $node = $event->getNode();
        $mount = $node->getMountPoint();
        if ($mount) {
            $options = $mount->getOptions();
            $globalDefault = \OC::$server->getConfig()
                ->getAppValue('files_external', 'default_no_trashbin', 'false');

            $mountClass = get_class($mount);
            if (str_contains($mountClass, 'OCA\\Files_External') && $globalDefault === 'true' || !empty($options['no_trashbin'])) {
                $event->disableTrashBin();
            }
        }
    }
}
PHP

# Patch Application.php
APP_FILE="$NC_DIR/apps/files_external/lib/AppInfo/Application.php"

echo "[INFO] Patch Application.php..."
if ! grep -q "MoveToTrashEvent" "$APP_FILE"; then
    #Insert import (if not present)
    sed -i '/use OCA\\Files_External\\Listener\\UserDeletedListener;/a use OCA\\Files_External\\Listener\\MoveToTrashListener;\nuse OCA\\Files_Trashbin\\Events\\MoveToTrashEvent;' "$APP_FILE"

    #Register the listener in the register() method
    sed -i "/\$context->registerEventListener(UserDeletedEvent::class/a \    \$context->registerEventListener(MoveToTrashEvent::class, MoveToTrashListener::class);" "$APP_FILE"
else
    echo "[INFO] Application.php already patched – skip."
fi

COMPOSER_PATH="$NC_DIR/apps/files_external/composer/composer"

# 1️autoload_classmap.php patchen
CLASSMAP="$COMPOSER_PATH/autoload_classmap.php"
if ! grep -q "MoveToTrashListener" "$CLASSMAP"; then
    sed -i "/OCA\\\\\\\\Files_External\\\\\\\\Listener\\\\\\\\UserDeletedListener/a \    'OCA\\\\\\\\Files_External\\\\\\\\Listener\\\\\\\\MoveToTrashListener' => \$baseDir . '/../lib/Listener/MoveToTrashListener.php'," "$CLASSMAP"
    echo "[INFO] autoload_classmap.php patched"
else
    echo "[INFO] autoload_classmap.php already contains MoveToTrashListener"
fi

# autoload_static.php patchen
STATIC="$COMPOSER_PATH/autoload_static.php"
if ! grep -q "MoveToTrashListener" "$STATIC"; then
    sed -i "/OCA\\\\\\\\Files_External\\\\\\\\Listener\\\\\\\\UserDeletedListener/a \        'OCA\\\\\\\\Files_External\\\\\\\\Listener\\\\\\\\MoveToTrashListener' => __DIR__ . '/..' . '/../lib/Listener/MoveToTrashListener.php'," "$STATIC"
    echo "[+] autoload_static.php patched"
else
    echo "[i] autoload_static.php enthält bereits MoveToTrashListener"
fi

# Set optional global app config
echo "[INFO] Set global app config (default_no_trashbin=true)..."
sudo -u www-data php "$NC_DIR/occ" config:app:set files_external default_no_trashbin --value=true

echo "[INFO] Set owner of the files to www-data restart apache2!"
chown -cR www-data:www-data /var/www/nextcloud/apps/files_external/
service apache2 restart

echo "[INFO] Patch completed!"
echo "[INFO] Try deleting files from external storage -> they should disappear immediately."

JanisPlayer avatar Aug 26 '25 12:08 JanisPlayer