From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: function for cleaning org-attach directories Date: Fri, 17 Jul 2015 13:19:19 +0800 Message-ID: <87vbdjico8.fsf@ericabrahamsen.net> References: <877fq0o4xx.fsf@ericabrahamsen.net> <87d1zs46jm.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFy3X-0007gV-JT for emacs-orgmode@gnu.org; Fri, 17 Jul 2015 01:19:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFy3U-0002JV-Av for emacs-orgmode@gnu.org; Fri, 17 Jul 2015 01:19:31 -0400 Received: from plane.gmane.org ([80.91.229.3]:44427) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFy3U-0002JR-4S for emacs-orgmode@gnu.org; Fri, 17 Jul 2015 01:19:28 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZFy3R-0007CU-G0 for emacs-orgmode@gnu.org; Fri, 17 Jul 2015 07:19:26 +0200 Received: from 221.220.58.77 ([221.220.58.77]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 17 Jul 2015 07:19:25 +0200 Received: from eric by 221.220.58.77 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 17 Jul 2015 07:19:25 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Eric Abrahamsen writes: > Alan Schmitt writes: > >> Hi Eric, >> >> On 2015-07-16 10:57, Eric Abrahamsen writes: >> >>> I use org-attach a lot, and if you're not careful you can get a "data/" >>> directory of many gigabytes. Not a problem, until you want to rsync it >>> and it takes all day... >>> >>> I wrote this to clean my attach directories. I'm not sure how portable >>> it is (and I'm really not pleased with the (concat attach-dir "/" d "/" >>> d+)), but I'm posting it to see if it's useful to anyone. >>> >>> Comments/improvements welcome! If the final product is desirable, I can >>> work it up as a patch. >> >> This would be most useful indeed. One quick question: why do you use >> "rm" instead of "delete-file"? > > Because I was copy-pasting from org-attach! The real question is: why > didn't I use `delete-directory' :) > > I'll do another version! > > E Here we go, and this one ought to be a little more portable. I guess I'll do it as a proper patch in a bit. (defun org-attach-clean-dirs (&optional attach-dir clean-archived) (interactive) (let ((attach-dir (if attach-dir (file-name-as-directory attach-dir) (concat (file-name-as-directory org-directory) org-attach-directory))) (valid-dir-re "\\`[0-9a-z-]+\\'") (org-id-search-archives (if clean-archived nil org-id-search-archives))) (dolist (d (directory-files attach-dir nil valid-dir-re)) (dolist (d+ (directory-files (concat attach-dir d) nil valid-dir-re)) (let ((id (format "%s%s" d d+)) (full-path (concat attach-dir (file-name-as-directory d) d+))) (unless (org-id-find id) (delete-directory full-path t)))))))