Skip to content

Commit 6a18890

Browse files
committed
Ensure directory exists before searching for a .cabal file
1 parent 74f85f0 commit 6a18890

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

haskell-cabal.el

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,24 @@ 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+
(valid-dir (when (file-directory-p use-dir) use-dir)))
216+
(when valid-dir
217+
(catch 'found
218+
(let ((user (nth 2 (file-attributes valid-dir)))
219+
;; Abbreviate, so as to stop when we cross ~/.
220+
(root (abbreviate-file-name valid-dir)))
221+
;; traverse current dir up to root as long as file owner doesn't change
222+
(while (and root (equal user (nth 2 (file-attributes root))))
223+
(let ((cabal-file (haskell-cabal-find-pkg-desc root)))
224+
(when cabal-file
225+
(throw 'found cabal-file)))
226+
227+
(let ((proot (file-name-directory (directory-file-name root))))
228+
(if (equal proot root) ;; fix-point reached?
229+
(throw 'found nil)
230+
(setq root proot))))
231+
nil)))))
229232

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

0 commit comments

Comments
 (0)