[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/disk-usage 0c135ed 21/48: Handle inaccessible directori
From: |
Stefan Monnier |
Subject: |
[elpa] externals/disk-usage 0c135ed 21/48: Handle inaccessible directories |
Date: |
Tue, 19 Feb 2019 08:00:00 -0500 (EST) |
branch: externals/disk-usage
commit 0c135ed0b6f65581ed25d59a373ae0545499dbac
Author: Pierre Neidhardt <address@hidden>
Commit: Pierre Neidhardt <address@hidden>
Handle inaccessible directories
---
disk-usage.el | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/disk-usage.el b/disk-usage.el
index 0a13cfc..ca9efb5 100644
--- a/disk-usage.el
+++ b/disk-usage.el
@@ -61,6 +61,12 @@
:type '(choice (function :tag "Native (slow)"
disk-usage--directory-size-with-emacs)
(function :tag "System \"du\""
disk-usage--directory-size-with-du)))
+(defface disk-usage-inaccessible
+ '((t :foreground "red"
+ :underline t))
+ "Face for inaccessible folders."
+ :group 'disk-usage)
+
(defface disk-usage-symlink
'((t :foreground "orange"))
"Face for symlinks."
@@ -94,7 +100,8 @@
(defun disk-usage--list (directory)
(setq directory (or directory default-directory))
- (let ((listing (directory-files-and-attributes directory 'full nil 'nosort)))
+ (let ((listing (and (file-accessible-directory-p directory)
+ (directory-files-and-attributes directory 'full nil
'nosort))))
(or (cl-loop for l in listing
for attributes = (cl-rest l)
for path = (cl-first l)
@@ -117,6 +124,7 @@
(defvar disk-usage--du-command "du")
(defvar disk-usage--du-args "-sb")
(defvar disk-usage--find-command "find")
+
(defun disk-usage--list-recursively (directory)
"This is the equivalent of running the shell command
$ find . -type f -exec du -sb {} +"
@@ -125,7 +133,7 @@ $ find . -type f -exec du -sb {} +"
(let ((pair (split-string s "\t")))
(vector (string-to-number (cl-first pair)) (cadr pair))))
(split-string (with-temp-buffer
- (call-process "find" nil t nil
+ (call-process "find" nil '(t nil) nil
directory
"-type" "f"
"-exec" disk-usage--du-command
disk-usage--du-args "{}" "+")
@@ -175,7 +183,7 @@ This is slow but does not require any external process."
(with-temp-buffer
(with-output-to-string
(call-process disk-usage--du-command
- nil t nil
+ nil '(t nil) nil
disk-usage--du-args path))
(buffer-string))))))
@@ -209,7 +217,6 @@ Takes a number and returns a string.
(defun disk-usage--refresh (&optional directory)
(setq directory (or directory default-directory))
- ;; TODO: Set tabulated-list-entries to a function?
(let ((listing (funcall disk-usage-list-function directory)))
(disk-usage--set-format (disk-usage--total listing))
(tabulated-list-init-header)
@@ -252,12 +259,18 @@ FILE-ENTRY may be a string or a button."
(let* ((filename (if (listp file-entry)
(cl-first file-entry)
file-entry))
- (formatted-filename (if (stringp (file-attribute-type
(file-attributes filename)))
- (propertize (funcall disk-usage--format-files
filename)
- 'face (if (file-directory-p
filename)
-
'disk-usage-symlink-directory
- 'disk-usage-symlink))
- (funcall disk-usage--format-files filename))))
+ (formatted-filename
+ (cond
+ ((stringp (file-attribute-type (file-attributes filename)))
+ (propertize (funcall disk-usage--format-files filename)
+ 'face (if (file-directory-p filename)
+ 'disk-usage-symlink-directory
+ 'disk-usage-symlink)))
+ ((and (not (null (file-attribute-type (file-attributes filename))))
+ (not (file-accessible-directory-p filename)))
+ (propertize (funcall disk-usage--format-files filename)
+ 'face 'disk-usage-inaccessible))
+ (t (funcall disk-usage--format-files filename)))))
(if (listp file-entry)
(let ((copy (cl-copy-list file-entry)))
(setcar copy formatted-filename)
@@ -306,6 +319,8 @@ beings."
;;;###autoload
(defun disk-usage (&optional directory)
(interactive "D")
+ (unless (file-accessible-directory-p directory)
+ (error "Directory cannot be opened: %S" directory))
(unless disk-usage--cache
(setq disk-usage--cache (make-hash-table :test #'equal)))
(setq directory (file-truename (or (and (file-directory-p directory)
- [elpa] externals/disk-usage f330f01 31/48: Fix structure manipulation in disk-usage-by-types, (continued)
- [elpa] externals/disk-usage f330f01 31/48: Fix structure manipulation in disk-usage-by-types, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 00aa40a 10/48: Bind "S-<return>" to disk-usage-find-file-at-point, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 4fc5cb3 33/48: Refresh cache with prefix argument, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 1949c82 37/48: Add disk-usage-by-types-here, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage f3895a3 27/48: Normalize some function names, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 0d4ce4b 12/48: Bind "^" and "<backspace>" to disk-usage-up, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage aa3996e 24/48: Default to disk-usage--list, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 90607dc 23/48: Use file-info structure instead of vectors, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage ed9dc23 11/48: Keep cursor on current entry when re-ordering buffer, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage dcfbd19 29/48: Rename sort functions, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 0c135ed 21/48: Handle inaccessible directories,
Stefan Monnier <=
- [elpa] externals/disk-usage 19103ba 42/48: Add unmark-at-point, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 3357ba9 32/48: Include screenshots, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 2626642 15/48: Remove spurious "evil" keyword, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage eefa57f 28/48: Turn disk-usage-size-format-function into a defcustom, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage af22dd4 13/48: Display symlinks when not displaying full paths, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 3ffaf8e 14/48: Fix header display, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 7fe5f1b 40/48: Fix keymap setup in disk-usage-by-types-mode, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage d959b7b 36/48: Display % column and sort types by total size, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 3bbb09a 44/48: Right-align columns with units, Stefan Monnier, 2019/02/19
- [elpa] externals/disk-usage 441abf9 20/48: Add disk-usage-by-types, Stefan Monnier, 2019/02/19