Survey -- Move To Trash function in Python?

Chris Angelico rosuav at gmail.com
Fri May 15 00:25:45 EDT 2015


On Fri, May 15, 2015 at 2:09 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
>> Yes, but sometimes it's at the file system's discretion - particularly
>> when you're working with network mounts. The application may not even
>> know that the file got hard deleted.
>
> Citation needed.
>
> "Move to trash" is a move operation, not an unlink. By definition, it is
> reversible. Which platforms/file systems implements it as an unlink?
>
> (I think the answer is, "broken ones".)

With individual files, you're right that it's broken systems; I do
recall having some setups with network mounts where the "trash"
request was sent over to a remote system and that system, for whatever
reason, chose to delete since it was unable to trash. However, it's
worth noting that a lot of trash cans have strict capacity
limitations, and trashing an entire directory may well result in most
of its content being hard-deleted (or, to be technically correct,
trashed and then purged before the user had a chance to do anything).
And to add insult to injury, some systems (which shall remain
nameless, despite being well known for using UTF-16 file names and
other such anomalies) have such appalling trash-management algorithms
that deleting an entire directory becomes a ridiculously slow
operation - I suspect there's some sort of O(n) linear search being
done for every trashed file, resulting in quadratic performance for
trashing a directory. And when the directory in question is a set of
files that can't usefully be used individually, I'd really rather tell
the application to just hard-delete the whole lot... but that
application didn't even give that option. Anyway.

The main thing is that trashing invites the system to delete the file
at its leisure, so it'll consume disk space and be undeletable for an
unspecified and highly uncertain period of time. If you're depending
on your trash can to protect you, you're just as vulnerable as someone
who depends on disk-level undeletion. There's no solution to that; it
comes down to one of the two hardest problems in computing (cache
management).

ChrisA



More information about the Python-list mailing list