summaryrefslogtreecommitdiff
path: root/lisp/files.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2008-02-16 21:39:31 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2008-02-16 21:39:31 +0000
commit5ffc4c051fbd91cd53430b560c6fd914c8b676a0 (patch)
tree2dfb650b3fa39e8b46c1e868e34c417a4f25a4bb /lisp/files.el
parent6c7b01b61e42336eb57a722eb51ed04ce1a87376 (diff)
downloademacs-5ffc4c051fbd91cd53430b560c6fd914c8b676a0.tar.gz
(locate-dominating-file): Remove initial loop because it's
not careful enough. Detect the uid-change all within the main loop.
Diffstat (limited to 'lisp/files.el')
-rw-r--r--lisp/files.el20
1 files changed, 12 insertions, 8 deletions
diff --git a/lisp/files.el b/lisp/files.el
index ffa8e0a328f..82f190a013f 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -727,18 +727,22 @@ PATH-AND-SUFFIXES is a pair of lists, (DIRECTORIES . SUFFIXES)."
(defun locate-dominating-file (file regexp)
"Look up the directory hierarchy from FILE for a file matching REGEXP."
- (while (and file (not (file-directory-p file)))
- (setq file (file-name-directory (directory-file-name file))))
(catch 'found
- (let ((user (nth 2 (file-attributes file)))
+ ;; `user' is not initialized yet because `file' may not exist, so we may
+ ;; have to walk up part of the hierarchy before we find the "initial UID".
+ (let ((user nil)
;; Abbreviate, so as to stop when we cross ~/.
(dir (abbreviate-file-name (file-name-as-directory file)))
files)
- ;; As a heuristic, we stop looking up the hierarchy of directories as
- ;; soon as we find a directory belonging to another user. This should
- ;; save us from looking in things like /net and /afs. This assumes
- ;; that all the files inside a project belong to the same user.
- (while (and dir (equal user (nth 2 (file-attributes dir))))
+ (while (and dir
+ ;; As a heuristic, we stop looking up the hierarchy of
+ ;; directories as soon as we find a directory belonging to
+ ;; another user. This should save us from looking in
+ ;; things like /net and /afs. This assumes that all the
+ ;; files inside a project belong to the same user.
+ (let ((prev-user user))
+ (setq user (nth 2 (file-attributes file)))
+ (not (or (null prev-user) (equal user prev-user)))))
(if (setq files (directory-files dir 'full regexp))
(throw 'found (car files))
(if (equal dir