Skip to content

Commit 651785c

Browse files
committed
Merge pull request #520 from ivan-m/cabal-nonexistent-directories
Ensure directory exists before searching for a .cabal file
2 parents 139b2db + 4cdecb9 commit 651785c

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

haskell-cabal.el

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

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

0 commit comments

Comments
 (0)