[Bug]: Permanently deleting a single trash bin item leaves its row in oc_files_trash

Abierto Apto para principiantes
#66,674 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php

Línea de trabajo

Empieza por apps/files_trashbin/lib/Trash/LegacyTrashBackend.php, especialmente por removeItem(), y sigue la ruta que se pasa a Trashbin::delete() comparándola con el ID almacenado por move2trash(). Reproduce el problema eliminando permanentemente un único elemento de nivel superior de la papelera y comprobando si permanece su fila en oc_files_trash. Se considera resuelto cuando la eliminación del elemento individual borra esa fila junto con el archivo; el issue propone una posible solución que hay que investigar.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

35-feedback
⚠️ This issue respects the following points: ⚠️
  • This is not a troubleshooting question, general support matter, or webserver/proxy problem, but likely a bug.
  • This issue is not already reported on Github OR solved at the Community Help Forum (I've searched!).
  • I'm using a maintained major version of Nextcloud Server and tested against the latest patch level.
  • I agree to follow Nextcloud's Code of Conduct.
  • I've tried my best to provide clear reproduction steps that someone unfamiliar with this bug could use to reproduce it.
Bug description

Permanently deleting a single top-level item from the trash bin (Files → Deleted files → "Delete permanently", or a WebDAV DELETE on remote.php/dav/trashbin/<user>/trash/<name>.d<timestamp>) removes the file and its versions from disk, but its row in oc_files_trash stays, with the file name and its original location. Nothing removes that row afterwards, except emptying the whole trash bin or deleting the user.

The trash bin listing is unaffected, as it comes from the disk. But the name of a file the user believes permanently deleted remains in the database, and in every database backup.

Cause. For a root item, getTrashPath() starts with a slash (/name.d1700000000, which is what isRootItem() relies on). LegacyTrashBackend::removeItem() strips the .d<timestamp> suffix but keeps the slash, and passes /name to Trashbin::delete():

https://github.com/nextcloud/server/blob/0fba83d5205b4c74a17aef9511f6490d33eda6bb/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php#L88-L90

The file is deleted fine (the extra slash is harmless in a path), then deleteTrashRow($user, '/name', $timestamp) looks for id = '/name', while move2trash() stored id = 'name', so the DELETE matches no row:

https://github.com/nextcloud/server/blob/0fba83d5205b4c74a17aef9511f6490d33eda6bb/apps/files_trashbin/lib/Trashbin.php#L782
https://github.com/nextcloud/server/blob/0fba83d5205b4c74a17aef9511f6490d33eda6bb/apps/files_trashbin/lib/Trashbin.php#L788-L795

Same code on master, stable35, stable31 and stable30.

Possible fix, tested on 35.0.3 with the steps below: the row is then removed.

Trashbin::delete(ltrim($path, '/'), $user->getUID(), $item->getDeletedTime());
Steps to reproduce
  1. Fresh Nextcloud 35.0.3 (official Docker image, SQLite), a user alice
  2. Upload example.txt and other.txt, then delete both
  3. SELECT id, location, timestamp FROM oc_files_trash WHERE user = 'alice'; → two rows, example.txt and other.txt
  4. Permanently delete example.txt from the trash bin, e.g. curl -u alice -X DELETE http://localhost/remote.php/dav/trashbin/alice/trash/example.txt.d<timestamp> → 204
  5. The trash bin now lists other.txt only, and files_trashbin/files/ holds other.txt.d<timestamp> only
  6. Run the same SELECT again → both rows are still there

Control: emptying the whole trash bin (DELETE …/trashbin/alice/trash/) removes all rows, as expected. A file with versions behaves the same: its versions are removed from files_trashbin/versions/, its row stays.

Expected behavior

The row is removed together with the file, as when the whole trash bin is emptied.

Nextcloud Server version

35

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.5

Web server

Apache (supported)

Database engine version

SQLite

Is this bug present after an update or on a fresh install?

Fresh Nextcloud Server install

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?
  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other
Configuration report
{
    "system": {
        "htaccess.RewriteBase": "\/",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "apps_paths": [
            {
                "path": "\/var\/www\/html\/apps",
                "url": "\/apps",
                "writable": false
            },
            {
                "path": "\/var\/www\/html\/custom_apps",
                "url": "\/custom_apps",
                "writable": true
            }
        ],
        "upgrade.disable-web": true,
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "localhost",
            "localhost"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "sqlite3",
        "version": "35.0.3.2",
        "overwrite.cli.url": "http:\/\/localhost",
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "installed": true
    }
}
List of activated Apps
Default apps of a fresh 35.0.3 install, nothing added
Additional info

Also seen on PostgreSQL 18 with the same version.

Lenguaje dominante
PHP
Estrellas
37.5k
Forks
5.4k
Merge medio
1 d 13 h
PR fusionados (30 d)
639

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de nextcloud/server

Todos los issues de nextcloud/server

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.