Changeset 9283


Ignore:
Timestamp:
Apr 25, 2008, 10:10:16 PM (11 years ago)
Author:
mikel
Message:

modified basename to return a directory or filename pathname that reflects the type of the actual file or directory, if present

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/builder-utilities.lisp

    r8503 r9283  
    1717;;; application-building tools for building and copying bundles,
    1818;;; resource directories, and magic files used by OSX applications.
    19 
    2019
    2120(defun copy-nibfile (srcnib dest-directory &key (if-exists :overwrite))
     
    3837;;; filename (with type extension) if it names a file, or the
    3938;;; last directory name if it names a directory
    40 ;;; TODO: perhaps BASENAME should check the file or directory
    41 ;;;       named by PATH and ensure that, if the named file
    42 ;;;       or directory exists, then the choice of returning
    43 ;;;       a file or directory is based on what the actual target
    44 ;;;       is, rather than on what the text of PATH suggests?
    4539
    4640(defun basename (path)
    47   (let* ((dir (pathname-directory path))
     41  ;; first probe to see whether the path exists.  if it does, then
     42  ;; PROBE-FILE returns a canonical pathname for it which, among other
     43  ;; things, ensures the pathame represents a directory if it's really
     44  ;; a directory, and a file if it's really a file
     45  (let* ((path (or (probe-file path)
     46                   path))
     47         (dir (pathname-directory path))
    4848         (name (pathname-name path))
    4949         (type (pathname-type path)))
     
    5252            (make-pathname :name name :type type)
    5353            (make-pathname :name name))
    54         (make-pathname :directory (first (last dir))))))
     54        ;; it's possible to have a pathname with a type but no name
     55        ;; e.g. "/Users/foo/.emacs"
     56        (if type
     57            (make-pathname :type type)
     58            (make-pathname :directory (first (last dir)))))))
    5559
    5660;;; PATH (&rest components)
Note: See TracChangeset for help on using the changeset viewer.