Re: Trash system



#if Pavel Cisler
> > There's still the problem of the same username on 2 hosts making files
> > in .Trash-(user name). I'm not sure how to fix that.
> 
> Do you need to address that? Couldn't you just put items deleted on
> different hosts by the same user on the same partition into the same
> Trash?

There's the problem of UIDs not matching. That's the sysadmin's problem,
I suppose. Might as well forget about it.

Here's my current plan:

** Deleting a file.

Path to the original file = $ORIGPATH.
Basename of the original file = $ORIGNAME.
$TRASHPATH = $ORIGPATH/.Trash.

1.  stat $TRASHPATH
    ENOENT    ->  mkdir
                  Error other than EEXIST -> Fail.
                  No error                -> chdir
    !S_ISDIR  ->  Fail.

2.  stat "files"
    ENOENT    ->  mkdir
                  Error other than EEXIST -> Fail.
    !S_ISDIR  ->  Fail.
    
3.  stat "info"
    ENOENT    ->  mkdir
                  Error other than EEXIST -> Fail.
    !S_ISDIR  ->  Fail.

4.  stat "tmp"
    ENOENT    ->  mkdir
                  Error other than EEXIST -> Fail.
    !S_ISDIR  ->  Fail.

5.  Generate unique string -> $UNIQ

6.  stat $TRASHPATH/tmp/$UNIQ
    Error other than ENOENT -> Go to 5.

7.  open($TRASHPATH/tmp/$UNIQ, O_CREAT, 0600)
    Error -> Fail.

8.  write data.
    Error -> Fail.

9.  flush.
    Error -> Fail.

10. close.
    Error -> Fail.

11. rename($TRASHPATH/tmp/$UNIQ/, $TRASHPATH/info/$UNIQ)
    Error -> Fail.

12. rename($ORIGPATH/$ORIGNAME, $TRASHPATH/files/$UNIQ)
    Error -> Fail.

13. Generate hash of $TRASHPATH -> $HASH

14. symlink $TRASHPATH ~/.Trash/$HASH
    Error other than EEXIST -> Fail.

I stuck with ~/.Trash because I don't think there's a reason to change
it from what Nautilus is using already.

There are a few race conditions in this description, but nothing that
can cause loss of data or anything like that, I think.

Rik





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]