Skip to content

Commit

Permalink
Fix a bunch of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
akirak committed May 11, 2018
1 parent 693f9a9 commit 23b3323
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
11 changes: 6 additions & 5 deletions helm-linux-disks.el
Expand Up @@ -71,7 +71,7 @@
(interactive)
(let ((mountpoint (linux-disk-mountpoint struct)))
(unless mountpoint
(error "not mounted"))
(error "Not mounted"))
(helm-find-files-1 (file-name-as-directory mountpoint)))))
("info (udisksctl)" . linux-disk-udisksctl-info)
("power off the device" . linux-disk-udisksctl-poweroff))
Expand Down Expand Up @@ -100,7 +100,9 @@
:has-child-p has-child))))

(defun helm-linux-disks--lsblk-trim (raw)
"Trim control characters and white spaces from an output line of lsblk command."
"Trim control characters and white spaces from an output of lsblk command.
RAW is a line in the output of lsblk command."
(if (string-match "\\(/.+\\)$" raw)
(match-string 1 raw)
raw))
Expand All @@ -113,7 +115,7 @@
"-o" "name,mountpoint,fstype,type,size")))

(defun helm-linux-disks--lsblk-get-level (output)
"Get the level of a record from an output of lsblk command.
"Get the level of a record from an OUTPUT of lsblk command.
A level is the starting position of the first slash character."
(seq-position output ?/))
Expand All @@ -128,8 +130,7 @@ A level is the starting position of the first slash character."
(cl-loop for s in (process-lines "sudo" "vgs"
"--noheadings")
collect (cons s (car (split-string s)))))))
"An auxiliary Helm source containing a list of LVM volume groups for
`helm-linux-disks'.
"Helm source containing a list of LVM volume groups for `helm-linux-disks'.
This is useful for removing a device with a LVM physical volume.")

Expand Down
68 changes: 35 additions & 33 deletions linux-disk.el
Expand Up @@ -60,7 +60,7 @@
(string-equal (linux-disk-fstype struct) "crypto_LUKS"))

(defun linux-disk-luks-close-p (struct)
"Return non-nil if STRUCT is a closed LUKS volume. "
"Return non-nil if STRUCT is a closed LUKS volume."
(and (linux-disk-luks-p struct)
(not (linux-disk-has-child-p struct))))

Expand All @@ -79,8 +79,8 @@
"Mount (unlock) or unmount (lock) the device depending on the state of STRUCT.
STRUCT should be a `linux-disk' object. If the argument represents an unmounted
(locked) device, it is mounted (unlocked). If the argument represents a mounted
(unlocked) device, it is unmounted (locked)."
\(locked) device, it is mounted (unlocked). If the argument represents a mounted
\(unlocked) device, it is unmounted (locked)."
(cond
((linux-disk-mounted-p struct) (linux-disk-unmount struct))
((linux-disk-mountable-p struct) (linux-disk-mount struct))
Expand All @@ -96,22 +96,22 @@ STRUCT should be a `linux-disk' object. If the argument represents an unmounted
STRUCT must be a `linux-disk' object representing an unmounted file system
object."
(unless (linux-disk-mountable-p struct)
(error "not mountable"))
(error "Not mountable"))
(cond
((executable-find "udisksctl") (linux-disk-udisksctl-mount struct))
;; TODO: mount using mount
(t (error "udisksctl is not available"))))
(t (error "Command udisksctl is not available"))))

(defun linux-disk-unmount (struct)
"Unmount a file system volume.
STRUCT must be a `linux-disk' object representing an mounted file system object."
(unless (linux-disk-mounted-p struct)
(error "not mounted"))
(error "Not mounted"))
(cond
((executable-find "udisksctl") (linux-disk-udisksctl-unmount struct))
;; TODO: unmount using umount
(t (error "udisksctl is not available"))))
(t (error "Command udisksctl is not available"))))

;;;;; Operations using udisksctl

Expand All @@ -121,7 +121,7 @@ STRUCT must be a `linux-disk' object representing an mounted file system object.
STRUCT must be a `linux-disk' object representing an unmounted file system
object."
(unless (linux-disk-mountable-p struct)
(error "not mountable"))
(error "Not mountable"))
(let ((path (linux-disk-path struct)))
(message "mounting %s using udisksctl..." path)
(linux-disk--udisksctl-run "udisksctl-mount"
Expand All @@ -132,7 +132,7 @@ object."
STRUCT must be a `linux-disk' object representing a mounted file system object."
(unless (linux-disk-mounted-p struct)
(error "not mounted"))
(error "Not mounted"))
(if (linux-disk-ensure-unmountable (linux-disk-mountpoint struct))
(let ((path (linux-disk-path struct)))
(message "unmounting %s using udisksctl..." path)
Expand All @@ -145,7 +145,7 @@ STRUCT must be a `linux-disk' object representing a mounted file system object."
STRUCT must be a `linux-disk' object representing a closed LUKS device."
(unless (linux-disk-luks-open-p struct)
(error "not a decryption device"))
(error "Not a decryption device"))
(let ((path (linux-disk-path struct)))
(message "locking %s..." path)
(linux-disk--udisksctl-run "udisksctl-lock"
Expand All @@ -156,7 +156,7 @@ STRUCT must be a `linux-disk' object representing a closed LUKS device."
STRUCT must be a `linux-disk' object representing an open LUKS device."
(unless (linux-disk-luks-close-p struct)
(error "not a LUKS device"))
(error "Not a LUKS device"))
(let ((path (linux-disk-path struct)))
(message "unlocking %s..." path)
(eshell-command
Expand Down Expand Up @@ -207,7 +207,7 @@ normally has a dynamically mapped path like /dev/mapper/luks-XXXX."
(local-set-key "q" #'quit-window)
(setq buffer-read-only t))
(pop-to-buffer "*cryptsetup*")))
(error "not a decryption device")))
(error "Not a decryption device")))

;;;;; Running dired on the mount point

Expand All @@ -218,7 +218,7 @@ STRUCT should be a `linux-disk' object representing a mounted device. It also
needs to contain information on the mount point."
(let ((mountpoint (linux-disk-mountpoint struct)))
(unless mountpoint
(error "not mounted"))
(error "Not mounted"))
(dired mountpoint)))

(defun linux-disk-dired-other-window (struct)
Expand All @@ -228,19 +228,31 @@ STRUCT should be a `linux-disk' object representing a mounted device. It also
needs to contain information on the mount point."
(let ((mountpoint (linux-disk-mountpoint struct)))
(unless mountpoint
(error "not mounted"))
(error "Not mounted"))
(dired-other-window mountpoint)))

;;;;; Running terminal on the mount point

(defcustom linux-disk-terminal-type 'term
"Type of terminal invoked by `linux-disk-terminal' command.
If a string is given as the value of this variable, it is run as a terminal
program."
:type '(choice (const term)
(const ansi-term)
(const multi-term)
(const eshell)
string)
:group '(linux-disk helm-linux-disks))

(defun linux-disk-terminal (struct)
"Open a terminal on the mount point of STRUCT.
STRUCT should be a `linux-disk' object representing a mounted device. It also
needs to contain information on the mount point."
(let ((mountpoint (linux-disk-mountpoint struct)))
(unless mountpoint
(error "not mounted"))
(error "Not mounted"))
(let ((default-directory mountpoint))
(pcase linux-disk-terminal-type
('term (call-interactively 'term))
Expand All @@ -249,23 +261,12 @@ needs to contain information on the mount point."
('eshell (eshell t))
((pred stringp) (async-shell-command linux-disk-terminal-type))))))

(defcustom linux-disk-terminal-type 'term
"Type of terminal invoked by `linux-disk-terminal' command.
If a string is given as the value of this variable, it is run as a terminal
program."
:type '(choice (const term)
(const ansi-term)
(const multi-term)
(const eshell)
string)
:group '(linux-disk helm-linux-disks))

;;;; udisksctl utilities
(defconst linux-disk--udisksctl-buffer "*udisksctl*"
"The name of the buffer to keep the output from udisksctl.")

(defun linux-disk--udisksctl-run (name &rest args)
"Run udisksctl command with NAME as a process name and ARGS."
(with-current-buffer (get-buffer-create linux-disk--udisksctl-buffer)
(erase-buffer)
(local-set-key "q" #'quit-window)
Expand All @@ -276,6 +277,7 @@ If a string is given as the value of this variable, it is run as a terminal
:command (cons "udisksctl" args)))

(defun linux-disk--udisksctl-sentinel (_ event)
"Process sentinel for udisksctl responding to EVENT."
(when (or (string-prefix-p "failed with code " event)
(string-prefix-p "exited abnormally with code " event))
(message "udisksctl failed or exited abnormally with non-zero exit code")
Expand Down Expand Up @@ -313,7 +315,7 @@ This function may prompt some information to the user if needed."
(buffer-list)))

(defun linux-disk--buffer-under-root-p (root buf)
"Test if a buffer (BUF) is associated with a path under ROOT."
"Test if ROOT is an ancestor of BUF."
(cl-loop for path in (list (buffer-file-name buf)
(with-current-buffer buf default-directory))
when (and path
Expand All @@ -337,15 +339,18 @@ This is done by running either lsof (preferred) or fuser command."
(message "There is a process accessing %s:\n%s" mountpoint procs))
(null procs)))

(defconst linux-disk-lsof-buffer "*lsof*"
"The name of the buffer to display the output from lsof command.")

(defun linux-disk--lsof (path)
"Run lsof command on PATH and return its output."
(with-current-buffer (get-buffer-create linux-disk-lsof-buffer)
(erase-buffer)
(when (= 0 (call-process "lsof" nil '(t nil) nil path))
(buffer-string))))

(defconst linux-disk-lsof-buffer "*lsof*"
"The name of the buffer to display the output from lsof command.")
(defconst linux-disk-fuser-buffer "*fuser*"
"The name of the buffer to display the output from fuser command.")

(defun linux-disk--fuser (mountpoint)
"Run fuser command on MOUNTPOINT and return its output."
Expand All @@ -354,8 +359,5 @@ This is done by running either lsof (preferred) or fuser command."
(when (= 0 (call-process "fuser" nil '(t nil) nil "-m" mountpoint))
(buffer-string))))

(defconst linux-disk-fuser-buffer "*fuser*"
"The name of the buffer to display the output from fuser command.")

(provide 'linux-disk)
;;; linux-disk.el ends here

0 comments on commit 23b3323

Please sign in to comment.