all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Removing backup files corresponding to no longer existing files
@ 2011-05-08  7:39 Rasmus Villemoes
  2011-05-08 15:20 ` Pascal J. Bourguignon
  2011-05-24 20:35 ` Deniz Dogan
  0 siblings, 2 replies; 4+ messages in thread
From: Rasmus Villemoes @ 2011-05-08  7:39 UTC (permalink / raw
  To: help-gnu-emacs

Hi,

I use a couple of separate directories to store emacs backup files
(using backup-directory-alist). But this means that if I decide to
delete or move some project (which is in its own direcory), just
deleting or moving the directory leaves all the backup copies
behind. They will then stay in the backup directories forever.

Is there a way to tell emacs to remove backup files which no longer
correspond to an actual file?

It's probably not very difficult to write a little (shell/perl) script
to do this, but I was wondering if there is some builtin way which
I've overlooked.

Emacs 23.1.1 on Ubuntu 10.10, if it matters.

Thanks in advance,
Rasmus


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Removing backup files corresponding to no longer existing files
  2011-05-08  7:39 Removing backup files corresponding to no longer existing files Rasmus Villemoes
@ 2011-05-08 15:20 ` Pascal J. Bourguignon
  2011-05-09 21:49   ` Rasmus Villemoes
  2011-05-24 20:35 ` Deniz Dogan
  1 sibling, 1 reply; 4+ messages in thread
From: Pascal J. Bourguignon @ 2011-05-08 15:20 UTC (permalink / raw
  To: help-gnu-emacs

Rasmus Villemoes <burner+usenet@imf.au.dk> writes:

> Hi,
>
> I use a couple of separate directories to store emacs backup files
> (using backup-directory-alist). But this means that if I decide to
> delete or move some project (which is in its own direcory), just
> deleting or moving the directory leaves all the backup copies
> behind. They will then stay in the backup directories forever.
>
> Is there a way to tell emacs to remove backup files which no longer
> correspond to an actual file?
>
> It's probably not very difficult to write a little (shell/perl) script
> to do this, but I was wondering if there is some builtin way which
> I've overlooked.
>
> Emacs 23.1.1 on Ubuntu 10.10, if it matters.

I have:

-----(clean-old-versions)-----------------------------------------------
#!/bin/bash 
dirs=()
do=
for arg ; do 
    case "$arg" in
    -n) do=echo ;;
    -*) echo "Usage:"
        echo "   $(basename $0) [-n] [directory ...]"
        echo "Remove all backup files that don't have a head."
        echo "If no directory is specified, then clean the current directory." 
        echo "-n only shows what would be done."
        exit 1
        ;;
    *)  dirs[${#dirs}]="$arg" ;;
    esac
done
if [ ${#dirs[@]} -eq 0 ] ; then
    dirs=(.)
fi
for dir in "${dirs[@]}" ; do 
    find "$dir" -maxdepth 1 \( -name \*~ -o -name .\?\*~ \) -print  \
    |while read file ; do 
        base="$(echo "$file" | sed -e 's/\(\.~[.0-9]\+\)\?~$//')"
        if [ ! -e "$base" ] ; then
            $do rm -v "$file" 
        fi
     done
done
------------------------------------------------------------------------

Indeed, it wouldn't be too hard to write it in emacs lisp either.  
The question would be when to run it?

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Removing backup files corresponding to no longer existing files
  2011-05-08 15:20 ` Pascal J. Bourguignon
@ 2011-05-09 21:49   ` Rasmus Villemoes
  0 siblings, 0 replies; 4+ messages in thread
From: Rasmus Villemoes @ 2011-05-09 21:49 UTC (permalink / raw
  To: help-gnu-emacs

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

> I have:
>
> -----(clean-old-versions)-----------------------------------------------

Thanks! I'll steal a couple of ideas from that script (but I need to
add a little extra: if a backup file corresponds to a file on a remote
file system, the file should be assumed to exist if the file system is
not currently mounted)

> Indeed, it wouldn't be too hard to write it in emacs lisp either.  
> The question would be when to run it?

Yes, I also thought a bit about that. But as long as emacs doesn't
keep a database of backup files, it's pretty safe to just delete them
using an auxilliary script as the one you provided, and running it
manually from time to time is good enough for me.

-- 
Rasmus Villemoes
<http://rasmusvillemoes.dk/>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Removing backup files corresponding to no longer existing files
  2011-05-08  7:39 Removing backup files corresponding to no longer existing files Rasmus Villemoes
  2011-05-08 15:20 ` Pascal J. Bourguignon
@ 2011-05-24 20:35 ` Deniz Dogan
  1 sibling, 0 replies; 4+ messages in thread
From: Deniz Dogan @ 2011-05-24 20:35 UTC (permalink / raw
  To: help-gnu-emacs

On 2011-05-08 09:39, Rasmus Villemoes wrote:
 > Hi,
 >
 > I use a couple of separate directories to store emacs backup files
 > (using backup-directory-alist). But this means that if I decide to
 > delete or move some project (which is in its own direcory), just
 > deleting or moving the directory leaves all the backup copies
 > behind. They will then stay in the backup directories forever.
 >
 > Is there a way to tell emacs to remove backup files which no longer
 > correspond to an actual file?
 >
 > It's probably not very difficult to write a little (shell/perl) script
 > to do this, but I was wondering if there is some builtin way which
 > I've overlooked.
 >
 > Emacs 23.1.1 on Ubuntu 10.10, if it matters.
 >
 > Thanks in advance,
 > Rasmus

I'm a bit late to the party, but I wrote this Emacs Lisp function which 
should do what you want:

(defun delete-old-backups (directory)
   (interactive "DDirectory: ")
   (let ((files (directory-files directory t)))
     (dolist (pair backup-directory-alist)
       (dolist (file files)
         (when (string-match (car pair) file)
           (delete-file (expand-file-name file (cdr pair))))))))

As I don't make use of `backup-directory-alist' myself, I cannot test it 
easily.

You can do this in a slightly different way as well, passing the MATCH 
argument to `directory-files' instead of getting all of the files in 
that directory and checking the regexps afterwards.

Hope that helps!

Deniz



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-05-24 20:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-08  7:39 Removing backup files corresponding to no longer existing files Rasmus Villemoes
2011-05-08 15:20 ` Pascal J. Bourguignon
2011-05-09 21:49   ` Rasmus Villemoes
2011-05-24 20:35 ` Deniz Dogan

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.