all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Error not detected in make-directory
@ 2003-01-27  1:11 worley
  0 siblings, 0 replies; only message in thread
From: worley @ 2003-01-27  1:11 UTC (permalink / raw)


Emacs version: 21.2

Observed problem:

If one invokes make-directory interactively and gives it the name of
an existing, ordinary file, it will return with no error, and causing
no change to the file system.  Similarly, calling '(make-directory
"/exisitng/file/name" t)' in E-Lisp signals no error and causes
nothing to happen.  In either case, the user or E-Lisp proceeds on the
assumption that the given name exists and is a directory, which can
cause errors.

Investigation:

make-directory (lines 2890 et seq. in files.el) does not explicitly
check to see if the name provided as an argument, or any of its
apparent parent directory names, already exists in the filesystem as
non-directory entries.  In most cases, this condition causes an error
in a lower-level file-handling primitive, but in the case that the
name is an ordinary file, no lower-level primitive is called, so the
condition is not detected.

Fix:

This can be corrected by inserting the test indicated below into the
definition of make-directory:

(defun make-directory (dir &optional parents)
  "Create the directory DIR and any nonexistent parent dirs.
Interactively, the default choice of directory to create
is the current default directory for file names.
That is useful when you have visited a file in a nonexistent directory.

Noninteractively, the second (optional) argument PARENTS says whether
to create parent directories if they don't exist."
  (interactive
   (list (read-file-name "Make directory: " default-directory default-directory
                         nil nil)
         t))
  (let ((handler (find-file-name-handler dir 'make-directory)))
    (if handler
        (funcall handler 'make-directory dir parents)
      (if (not parents)
          (make-directory-internal dir)
        (let ((dir (directory-file-name (expand-file-name dir)))
              create-list)
          (while (not (file-exists-p dir))
            (setq create-list (cons dir create-list)
                  dir (directory-file-name (file-name-directory dir))))
>         ;; 'dir' is the lowest parent directory name that already exists.
>         ;; Make sure that it really is a directory.
>         (if (not (car-safe (file-attributes dir)))
>             (error "%s is not a directory" dir))
          (while create-list
            (make-directory-internal (car create-list))
            (setq create-list (cdr create-list))))))))

Dale

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-01-27  1:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-27  1:11 Error not detected in make-directory worley

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.