Unable to move existing file to trash


when trying to restore an old version from backup with anki 2.1.28 I stumbled into this error:

Clearly restarting the pc is not an option and of any usefulness… besides I can’t understand why it should put some file to trash. My feeling is it was trying to create b’.Trash-1000’ and I can’t see a reason why it didn’t manage to do (all permissions are set ok for this user).


Anki uses the python library send2trash to move files to the trash. If you think you’ve found a bug, please reproduce it then report it upstream.

Reading their site:

On Freedesktop platforms (Linux, BSD, etc.), you may not be able to efficiently trash some files. In these cases, an exception send2trash.TrashPermissionError is raised, so that the application can handle this case. This inherits from PermissionError (OSError on Python 2). Specifically, this affects files on a different device to the user’s home directory, where the root of the device does not have a .Trash directory, and we don’t have permission to create a .Trash-$UID directory.

So I guess we’re exactly in this situation and it should be handled directly in the application. I copied .local/share/Anki2 to /tmp that happens to be in a separate device and I have in fact no right to create /.Trash-1000 as it belongs to user root.

So I think the correct behaviour in this case would be to just unlink it. I can create a patch for this if you want to go along this line.


In this instance that may be acceptable solution, as Anki is creating automatic backups by default. I don’t think it would be a good idea to do the same thing for other things like profile deletion however - I’d rather the user was made aware of the issue than just irrecoverably deleting things.

I just made a patch but have not yet asked to pull it as it has a weird behaviour that I really cannot explain.

It just works fine for addons.

When you try to restore a backup it works as expected until it runs the hook profileLoaded. I installed some add-on that listen to that (eg: Image Occlusion) and trigger a funcion that uses mw.col that is None.

I really can’t see the relation between my code and this behaviour bu you @dae probably what is going on…

I can’t think of why that patch would cause the behaviour you describe. Still feel a bit uneasy about permanently deleting a profile when moving to the trash fails, but at least there is a confirmation popup first, and dumping an error at the user isn’t very friendly.