Trash spec 0.4

Waldo Bastian bastian at
Fri Sep 10 13:56:31 EEST 2004

On Thursday 09 September 2004 10:08, Alexander Larsson wrote:
> The right algorithm is:
> 1. Make up a name you haven't tried before
> 2. open (filename, O_CREAT|O_EXCL, mode)
> 3. if the open failed with EEXIST, there was already a file with that
> name. Goto 1.
> 4. Now you have a filedescriptor to a file that is atomically guaranteed
> to not have existed before. (Or, the open failed for another reason,
> such as out of space.)
> 5. Write the trashinfo file to the filedescriptor.
> 6. We're now guaranteed there is no file with the same name in the files
> subdir, so move the trashed file there.
> This also means the implementations *MUST* create the info files first.
> Otherwise you're not guaranteed that after the info file is created
> moving the trash file will not fail.

This version is much better indeed. However, it can still fail over NFS 
because NFS doesn't guarantee consistency between different clients. So there 
is a small theoretical possibility that two different clients both manage to 
create the same file with O_CREAT|O_EXCL. Not sure if that's worth solving, 
it's IMHO rather unlikely that a user trashes two files with the same 
filename at the same time from two different clients.

bastian at  |   Novell BrainShare Europe 2004   |  bastian at
bastian at  | 12-18 September, Barcelona, Spain |  bastian at
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : 

More information about the xdg mailing list