| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- (in-package #:photo-store)
- (defun aget (key alist)
- (cdr (assoc key alist :test #'equal)))
- ;; From 'Practical Common Lisp' by Peter Seibel
- (defun component-present-p (value)
- (and value (not (eql value :unspecific))))
- (defun directory-pathname-p (p)
- (and
- (not (component-present-p (pathname-name p)))
- (not (component-present-p (pathname-type p)))
- p))
- (defun pathname-as-directory (name)
- (let ((pathname (pathname name)))
- (when (wild-pathname-p pathname)
- (error "Can't reliably convert wild pathnames."))
- (if (not (directory-pathname-p name))
- (make-pathname
- :directory (append (or (pathname-directory pathname) (list :relative))
- (list (file-namestring pathname)))
- :name nil
- :type nil
- :defaults pathname)
- pathname)))
- (defun directory-wildcard (dirname)
- (make-pathname
- :name :wild
- :type #-clisp :wild #+clisp nil
- :defaults (pathname-as-directory dirname)))
- (defun list-directory (dirname)
- (when (wild-pathname-p dirname)
- (error "Can only list concrete directory names."))
- (let ((wildcard (directory-wildcard dirname)))
- #+(or sbcl cmu lispworks)
- (directory wildcard)
- #+openmcl
- (directory wildcard :directories t)
- #+allegro
- (directory wildcard :directories-are-files nil)
- #+clisp
- (nconc
- (directory wildcard)
- (directory (clisp-subdirectories-wildcard wildcard)))
- #-(or sbcl cmu lispworks openmcl allegro clisp)
- (error "list-directory not implemented")))
- #+clisp
- (defun clisp-subdirectories-wildcard (wildcard)
- (make-pathname
- :directory (append (pathname-directory wildcard) (list :wild))
- :name nil
- :type nil
- :defaults wildcard))
- (defun file-exists-p (pathname)
- #+(or sbcl lispworks openmcl)
- (probe-file pathname)
- #+(or allegro cmu)
- (or (probe-file (pathname-as-directory pathname))
- (probe-file pathname))
- #+clisp
- (or (ignore-errors
- (probe-file (pathname-as-file pathname)))
- (ignore-errors
- (let ((directory-form (pathname-as-directory pathname)))
- (when (ext:probe-directory directory-form)
- directory-form))))
- #-(or sbcl cmu lispworks openmcl allegro clisp)
- (error "file-exists-p not implemented"))
- (defun pathname-as-file (name)
- (let ((pathname (pathname name)))
- (when (wild-pathname-p pathname)
- (error "Can't reliably convert wild pathnames."))
- (if (directory-pathname-p name)
- (let* ((directory (pathname-directory pathname))
- (name-and-type (pathname (first (last directory)))))
- (make-pathname
- :directory (butlast directory)
- :name (pathname-name name-and-type)
- :type (pathname-type name-and-type)
- :defaults pathname))
- pathname)))
- (defun walk-directory (dirname fn &key directories (test (constantly t)))
- (labels
- ((walk (name)
- (cond
- ((directory-pathname-p name)
- (when (and directories (funcall test name))
- (funcall fn name))
- (when (funcall test name)
- (dolist (x (list-directory name)) (walk x))))
- ((funcall test name) (funcall fn name)))))
- (walk (pathname-as-directory dirname))))
|