[Gllug] Re: trash management

Dan Stevens (IAmAI) dan.stevens.iamai at gmail.com
Mon Jan 30 12:28:18 UTC 2006


Thanks for this. In return, I shall share my idea of approach.

My idea is to move files to a trash directory specified by a single
(user dependant) 'TRASH' environment variable(default '~/.trash').
However, your approach of having a .trash directory on every
filesystem is a good one, which I may pursue as a user options. As a
file is moved to trash, an entry is added to a file stored in the user
directory (probably '~/.trashman/files'. The format of the entry is
'filename:directory', which 'filename' is the name of the file and
'directory' is the absolute reference to the file's original location.
This file is then used to restore files to their original location.

Removing and restoration will be performed by separate commands. I
think it may be possible to program removal using a shell script,
however restoration may have to be programmed in C. Also, eventually I
would like a daemon that will manage the permanent removal of files in
trash.



On Mon, 30 Jan 2006 11:22:59 +0 00, t.clarke <tim at seacon.co.uk> wrote:
>
> From:  Tim Clarke  SEACON GROUP LTD, Tower Wharf, Northfleet, Kent, da11 9BD
> Telephone: +44 (0)1474 320000    Web:  www.seacon.co.uk
>
> Hi
>
> the following is an extract from my C program to 'safely' delete files.
> can send you the source if yu wish !
>
>
> regards
>
>
> Tim Clarke
>
>
> /*
> 'Remove Safely' program.
> Instead of simply deleting the file(s), the program attempts to rename them
> into a '.trash' directory on the same filesystem, or failing that attempts
> to copy them to a default /var/.trash' directory and then delete.
> Ideally, there needs to be a .trash directory on each mounted filesystem,
> to avoid unecessary copying. However, if disc space is at a premium,
> the lack of a .trash directory on that filesystem will cause immediate
> copying and deleting, thus freeing space on that filesystem.
> The program determines the filesystem .trash directory to use simply by
> attempting rename operations at the root level and 'working down', up to
> a level of 4 directories.   If you have filesystems mounted at a lower level,
> then simply increase the defined value DIRLIMIT appropriately.
> If a file being 'deleted' already has a copy of an earlier version within
> the destination .trash directory, it is appended with ~A and the rename
> operation tried again, up to '~Z'.  Thus up to 26 versions of the saved file
> may exist within the .trash directory before 'deletion' will fail.
> It is probably a good strategy to periodically irrevocably delete (using rm)
> the files building up within the .trash directories, or move them to a 'master
> archive' fiesystem !
> The files contained within the .trash directories are given filenames
> equivalent to their original full pathnames, but with '/' replaced by '\'.
> Thus file '/usr/tmp/abc' would (assuming directory /.trash exists) be renamed
> as '/.trash/usr\tmp\abc'.
> The /var/.trash directory can of course be a symbolic link to another
> directory on another filesystem, since it is only copied-to.
>
> NOTE:  if symbolic links are specified, it is the link that is renamed, not the
> the underlying file. However, if the link cannot be renamed (across filesystems)
> it is simply deleted as the underlying file still exists and there is no point
> in copying the data.
>
> Multiple files can be 'deleted', eg:  rms  a b c   or  rms * .
> Directories CANNOT be 'deleted'.
> */
>
> --------------------------------------------------------------------------------
> This E-Mail (and any files transmitted with it) is intended solely for the use
> of the individual or entity to whom it is addressed. If you have received it in
> error please notify the sender and delete the message.
>
>
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list