Skip to content

Commit f1930bd

Browse files
committed
Ensure directory exists before searching for a .cabal file
1 parent 72ec9fd commit f1930bd

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

haskell-cabal.el

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,23 @@ Return nil if no Cabal description file could be located via
211211
If DIR is nil, `default-directory' is used as starting point for
212212
directory traversal. Upward traversal is aborted if file owner
213213
changes. Uses`haskell-cabal-find-pkg-desc' internally."
214-
(catch 'found
215-
(let ((user (nth 2 (file-attributes (or dir default-directory))))
216-
;; Abbreviate, so as to stop when we cross ~/.
217-
(root (abbreviate-file-name (or dir default-directory))))
218-
;; traverse current dir up to root as long as file owner doesn't change
219-
(while (and root (equal user (nth 2 (file-attributes root))))
220-
(let ((cabal-file (haskell-cabal-find-pkg-desc root)))
221-
(when cabal-file
222-
(throw 'found cabal-file)))
223-
224-
(let ((proot (file-name-directory (directory-file-name root))))
225-
(if (equal proot root) ;; fix-point reached?
226-
(throw 'found nil)
227-
(setq root proot))))
228-
nil)))
214+
(let ((use-dir (or dir default-directory)))
215+
(when (file-directory-p use-dir)
216+
(catch 'found
217+
(let ((user (nth 2 (file-attributes use-dir)))
218+
;; Abbreviate, so as to stop when we cross ~/.
219+
(root (abbreviate-file-name use-dir)))
220+
;; traverse current dir up to root as long as file owner doesn't change
221+
(while (and root (equal user (nth 2 (file-attributes root))))
222+
(let ((cabal-file (haskell-cabal-find-pkg-desc root)))
223+
(when cabal-file
224+
(throw 'found cabal-file)))
225+
226+
(let ((proot (file-name-directory (directory-file-name root))))
227+
(if (equal proot root) ;; fix-point reached?
228+
(throw 'found nil)
229+
(setq root proot))))
230+
nil)))))
229231

230232
(defun haskell-cabal-find-pkg-desc (dir &optional allow-multiple)
231233
"Find a package description file in the directory DIR.

0 commit comments

Comments
 (0)