/[cmucl]/src/code/filesys.lisp
ViewVC logotype

Contents of /src/code/filesys.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.47 - (hide annotations)
Mon Apr 20 11:32:51 1998 UTC (16 years ago) by pw
Branch: MAIN
Changes since 1.46: +82 -43 lines
This revision alters the condition type hierarchy to be in compliance
with the ANSI spec. A default report method is attached to the
serious-condition class and many of the uses of (error "string" arg..)
in filesys.lisp and package.lisp were changed to use, for example,
(error 'file-error :format-control "string" :format-arguments (list stuff))
The end result is no obvious change to what the user sees, and enables
one to establish a handler to catch the particular error type as
mentioned in the "Exceptional Situations:" section of the CLHS
write-ups. There probably are still some places where the error
types need to be fixed.

Also, a bug in with-package-iterator which caused failure with
a null package-use-list was fixed, and some file functions (like
truename and probe-file) now disallow a wild pathname.
1 ram 1.1 ;;; -*- Log: code.log; Package: Lisp -*-
2     ;;; **********************************************************************
3 ram 1.8 ;;; This code was written as part of the CMU Common Lisp project at
4     ;;; Carnegie Mellon University, and has been placed in the public domain.
5     ;;; If you want to use this code or any part of CMU Common Lisp, please contact
6     ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
7     ;;;
8     (ext:file-comment
9 pw 1.47 "$Header: /tiger/var/lib/cvsroots/cmucl/src/code/filesys.lisp,v 1.47 1998/04/20 11:32:51 pw Exp $")
10 ram 1.8 ;;;
11 ram 1.1 ;;; **********************************************************************
12     ;;;
13 wlott 1.16 ;;; File system interface functions. This file is pretty UNIX specific.
14 ram 1.1 ;;;
15 wlott 1.16 ;;; Written by William Lott
16 ram 1.1 ;;;
17     ;;; **********************************************************************
18 ram 1.2
19     (in-package "LISP")
20    
21 wlott 1.16 (export '(truename probe-file user-homedir-pathname directory
22     rename-file delete-file file-write-date file-author))
23 ram 1.1
24     (use-package "EXTENSIONS")
25    
26     (in-package "EXTENSIONS")
27     (export '(print-directory complete-file ambiguous-files default-directory
28 wlott 1.5 file-writable unix-namestring))
29 ram 1.2 (in-package "LISP")
30 ram 1.1
31 wlott 1.5
32 wlott 1.16 ;;;; Unix pathname host support.
33 ram 1.1
34 wlott 1.16 ;;; Unix namestrings have the following format:
35     ;;;
36     ;;; namestring := [ directory ] [ file [ type [ version ]]]
37     ;;; directory := [ "/" | search-list ] { file "/" }*
38     ;;; search-list := [^:/]*:
39     ;;; file := [^/]*
40     ;;; type := "." [^/.]*
41     ;;; version := "." ([0-9]+ | "*")
42     ;;;
43     ;;; Note: this grammer is ambiguous. The string foo.bar.5 can be parsed
44     ;;; as either just the file specified or as specifying the file, type, and
45     ;;; version. Therefore, we use the following rules when confronted with
46     ;;; an ambiguous file.type.version string:
47     ;;;
48     ;;; - If the first character is a dot, it's part of the file. It is not
49     ;;; considered a dot in the following rules.
50     ;;;
51     ;;; - If there is only one dot, it seperates the file and the type.
52     ;;;
53     ;;; - If there are multiple dots and the stuff following the last dot
54     ;;; is a valid version, then that is the version and the stuff between
55     ;;; the second to last dot and the last dot is the type.
56     ;;;
57     ;;; Wildcard characters:
58     ;;;
59     ;;; If the directory, file, type components contain any of the following
60     ;;; characters, it is considered part of a wildcard pattern and has the
61     ;;; following meaning.
62     ;;;
63     ;;; ? - matches any character
64     ;;; * - matches any zero or more characters.
65     ;;; [abc] - matches any of a, b, or c.
66     ;;; {str1,str2,...,strn} - matches any of str1, str2, ..., or strn.
67     ;;;
68     ;;; Any of these special characters can be preceeded by a backslash to
69     ;;; cause it to be treated as a regular character.
70     ;;;
71 ram 1.1
72 wlott 1.16 (defun remove-backslashes (namestr start end)
73     "Remove and occurences of \\ from the string because we've already
74     checked for whatever they may have been backslashed."
75     (declare (type simple-base-string namestr)
76     (type index start end))
77     (let* ((result (make-string (- end start)))
78     (dst 0)
79     (quoted nil))
80     (do ((src start (1+ src)))
81     ((= src end))
82     (cond (quoted
83     (setf (schar result dst) (schar namestr src))
84     (setf quoted nil)
85     (incf dst))
86     (t
87     (let ((char (schar namestr src)))
88     (cond ((char= char #\\)
89     (setq quoted t))
90     (t
91     (setf (schar result dst) char)
92     (incf dst)))))))
93     (when quoted
94     (error 'namestring-parse-error
95     :complaint "Backslash in bad place."
96     :namestring namestr
97     :offset (1- end)))
98     (shrink-vector result dst)))
99 ram 1.1
100 wlott 1.16 (defvar *ignore-wildcards* nil)
101 ram 1.1
102 wlott 1.16 (defun maybe-make-pattern (namestr start end)
103     (declare (type simple-base-string namestr)
104     (type index start end))
105     (if *ignore-wildcards*
106     (subseq namestr start end)
107     (collect ((pattern))
108     (let ((quoted nil)
109     (any-quotes nil)
110     (last-regular-char nil)
111     (index start))
112     (flet ((flush-pending-regulars ()
113     (when last-regular-char
114     (pattern (if any-quotes
115     (remove-backslashes namestr
116     last-regular-char
117     index)
118     (subseq namestr last-regular-char index)))
119     (setf any-quotes nil)
120     (setf last-regular-char nil))))
121     (loop
122     (when (>= index end)
123     (return))
124     (let ((char (schar namestr index)))
125     (cond (quoted
126     (incf index)
127     (setf quoted nil))
128     ((char= char #\\)
129     (setf quoted t)
130     (setf any-quotes t)
131     (unless last-regular-char
132     (setf last-regular-char index))
133     (incf index))
134     ((char= char #\?)
135     (flush-pending-regulars)
136     (pattern :single-char-wild)
137     (incf index))
138     ((char= char #\*)
139     (flush-pending-regulars)
140     (pattern :multi-char-wild)
141     (incf index))
142     ((char= char #\[)
143     (flush-pending-regulars)
144     (let ((close-bracket
145     (position #\] namestr :start index :end end)))
146     (unless close-bracket
147     (error 'namestring-parse-error
148     :complaint "``['' with no corresponding ``]''"
149     :namestring namestr
150     :offset index))
151     (pattern (list :character-set
152     (subseq namestr
153     (1+ index)
154     close-bracket)))
155     (setf index (1+ close-bracket))))
156     (t
157     (unless last-regular-char
158     (setf last-regular-char index))
159     (incf index)))))
160     (flush-pending-regulars)))
161     (cond ((null (pattern))
162     "")
163 ram 1.31 ((null (cdr (pattern)))
164     (let ((piece (first (pattern))))
165     (typecase piece
166     ((member :multi-char-wild) :wild)
167     (simple-string piece)
168     (t
169     (make-pattern (pattern))))))
170 wlott 1.16 (t
171     (make-pattern (pattern)))))))
172 ram 1.1
173 wlott 1.16 (defun extract-name-type-and-version (namestr start end)
174     (declare (type simple-base-string namestr)
175     (type index start end))
176     (let* ((last-dot (position #\. namestr :start (1+ start) :end end
177     :from-end t))
178     (second-to-last-dot (and last-dot
179     (position #\. namestr :start (1+ start)
180     :end last-dot :from-end t)))
181     (version :newest))
182     ;; If there is a second-to-last dot, check to see if there is a valid
183     ;; version after the last dot.
184     (when second-to-last-dot
185     (cond ((and (= (+ last-dot 2) end)
186     (char= (schar namestr (1+ last-dot)) #\*))
187     (setf version :wild))
188     ((and (< (1+ last-dot) end)
189     (do ((index (1+ last-dot) (1+ index)))
190     ((= index end) t)
191     (unless (char<= #\0 (schar namestr index) #\9)
192     (return nil))))
193     (setf version
194     (parse-integer namestr :start (1+ last-dot) :end end)))
195     (t
196     (setf second-to-last-dot nil))))
197     (cond (second-to-last-dot
198     (values (maybe-make-pattern namestr start second-to-last-dot)
199     (maybe-make-pattern namestr
200     (1+ second-to-last-dot)
201     last-dot)
202     version))
203     (last-dot
204     (values (maybe-make-pattern namestr start last-dot)
205     (maybe-make-pattern namestr (1+ last-dot) end)
206     version))
207     (t
208     (values (maybe-make-pattern namestr start end)
209     nil
210     version)))))
211 ram 1.1
212 ram 1.31 ;;; Take a string and return a list of cons cells that mark the char
213     ;;; separated subseq. The first value t if absolute directories location.
214     ;;;
215     (defun split-at-slashes (namestr start end)
216     (declare (type simple-base-string namestr)
217 wlott 1.16 (type index start end))
218     (let ((absolute (and (/= start end)
219 ram 1.31 (char= (schar namestr start) #\/))))
220 wlott 1.16 (when absolute
221     (incf start))
222 ram 1.31 ;; Next, split the remainder into slash seperated chunks.
223 wlott 1.16 (collect ((pieces))
224     (loop
225 ram 1.31 (let ((slash (position #\/ namestr :start start :end end)))
226     (pieces (cons start (or slash end)))
227     (unless slash
228 wlott 1.16 (return))
229 ram 1.31 (setf start (1+ slash))))
230 wlott 1.16 (values absolute (pieces)))))
231 ram 1.1
232 wlott 1.16 (defun maybe-extract-search-list (namestr start end)
233     (declare (type simple-base-string namestr)
234     (type index start end))
235     (let ((quoted nil))
236     (do ((index start (1+ index)))
237     ((= index end)
238     (values nil start))
239     (if quoted
240     (setf quoted nil)
241     (case (schar namestr index)
242     (#\\
243     (setf quoted t))
244     (#\:
245     (return (values (remove-backslashes namestr start index)
246     (1+ index)))))))))
247 ram 1.1
248 wlott 1.16 (defun parse-unix-namestring (namestr start end)
249     (declare (type simple-base-string namestr)
250     (type index start end))
251     (multiple-value-bind
252     (absolute pieces)
253     (split-at-slashes namestr start end)
254     (let ((search-list
255     (if absolute
256     nil
257     (let ((first (car pieces)))
258     (multiple-value-bind
259     (search-list new-start)
260     (maybe-extract-search-list namestr
261     (car first) (cdr first))
262     (when search-list
263     (setf absolute t)
264     (setf (car first) new-start))
265     search-list)))))
266     (multiple-value-bind
267     (name type version)
268     (let* ((tail (car (last pieces)))
269     (tail-start (car tail))
270     (tail-end (cdr tail)))
271     (unless (= tail-start tail-end)
272     (setf pieces (butlast pieces))
273     (extract-name-type-and-version namestr tail-start tail-end)))
274     ;; Now we have everything we want. So return it.
275     (values nil ; no host for unix namestrings.
276     nil ; no devices for unix namestrings.
277     (collect ((dirs))
278     (when search-list
279     (dirs (intern-search-list search-list)))
280     (dolist (piece pieces)
281     (let ((piece-start (car piece))
282     (piece-end (cdr piece)))
283     (unless (= piece-start piece-end)
284 ram 1.31 (cond ((string= namestr ".." :start1 piece-start
285     :end1 piece-end)
286     (dirs :up))
287     ((string= namestr "**" :start1 piece-start
288     :end1 piece-end)
289     (dirs :wild-inferiors))
290     (t
291     (dirs (maybe-make-pattern namestr
292     piece-start
293     piece-end)))))))
294 wlott 1.25 (cond (absolute
295     (cons :absolute (dirs)))
296     ((dirs)
297     (cons :relative (dirs)))
298     (t
299     nil)))
300 wlott 1.16 name
301     type
302     version)))))
303 ram 1.1
304 wlott 1.16 (defun unparse-unix-host (pathname)
305     (declare (type pathname pathname)
306     (ignore pathname))
307     "Unix")
308 ram 1.1
309 wlott 1.16 (defun unparse-unix-piece (thing)
310     (etypecase thing
311 ram 1.31 ((member :wild) "*")
312 wlott 1.16 (simple-string
313     (let* ((srclen (length thing))
314     (dstlen srclen))
315     (dotimes (i srclen)
316     (case (schar thing i)
317     ((#\* #\? #\[)
318     (incf dstlen))))
319     (let ((result (make-string dstlen))
320     (dst 0))
321     (dotimes (src srclen)
322     (let ((char (schar thing src)))
323     (case char
324     ((#\* #\? #\[)
325     (setf (schar result dst) #\\)
326     (incf dst)))
327     (setf (schar result dst) char)
328     (incf dst)))
329     result)))
330     (pattern
331     (collect ((strings))
332     (dolist (piece (pattern-pieces thing))
333     (etypecase piece
334     (simple-string
335     (strings piece))
336     (symbol
337 ram 1.31 (ecase piece
338 wlott 1.16 (:multi-char-wild
339     (strings "*"))
340     (:single-char-wild
341 ram 1.31 (strings "?"))))
342 wlott 1.16 (cons
343     (case (car piece)
344     (:character-set
345     (strings "[")
346     (strings (cdr piece))
347     (strings "]"))
348     (t
349     (error "Invalid pattern piece: ~S" piece))))))
350     (apply #'concatenate
351     'simple-string
352     (strings))))))
353 ram 1.1
354 wlott 1.16 (defun unparse-unix-directory-list (directory)
355     (declare (type list directory))
356     (collect ((pieces))
357     (when directory
358     (ecase (pop directory)
359     (:absolute
360     (cond ((search-list-p (car directory))
361     (pieces (search-list-name (pop directory)))
362     (pieces ":"))
363     (t
364     (pieces "/"))))
365     (:relative
366     ;; Nothing special.
367     ))
368     (dolist (dir directory)
369     (typecase dir
370     ((member :up)
371     (pieces "../"))
372     ((member :back)
373     (error ":BACK cannot be represented in namestrings."))
374 ram 1.31 ((member :wild-inferiors)
375     (pieces "**/"))
376 wlott 1.16 ((or simple-string pattern)
377     (pieces (unparse-unix-piece dir))
378     (pieces "/"))
379     (t
380     (error "Invalid directory component: ~S" dir)))))
381     (apply #'concatenate 'simple-string (pieces))))
382 ram 1.1
383 wlott 1.16 (defun unparse-unix-directory (pathname)
384     (declare (type pathname pathname))
385     (unparse-unix-directory-list (%pathname-directory pathname)))
386    
387     (defun unparse-unix-file (pathname)
388     (declare (type pathname pathname))
389     (collect ((strings))
390     (let* ((name (%pathname-name pathname))
391     (type (%pathname-type pathname))
392     (type-supplied (not (or (null type) (eq type :unspecific))))
393     (version (%pathname-version pathname))
394     (version-supplied (not (or (null version) (eq version :newest)))))
395     (when name
396     (strings (unparse-unix-piece name)))
397     (when type-supplied
398     (unless name
399     (error "Cannot specify the type without a file: ~S" pathname))
400     (strings ".")
401     (strings (unparse-unix-piece type)))
402     (when version-supplied
403     (unless type-supplied
404     (error "Cannot specify the version without a type: ~S" pathname))
405     (strings (if (eq version :wild)
406     ".*"
407     (format nil ".~D" version)))))
408     (apply #'concatenate 'simple-string (strings))))
409 ram 1.1
410 wlott 1.16 (defun unparse-unix-namestring (pathname)
411     (declare (type pathname pathname))
412     (concatenate 'simple-string
413     (unparse-unix-directory pathname)
414     (unparse-unix-file pathname)))
415 ram 1.1
416 wlott 1.16 (defun unparse-unix-enough (pathname defaults)
417     (declare (type pathname pathname defaults))
418     (flet ((lose ()
419     (error "~S cannot be represented relative to ~S"
420     pathname defaults)))
421     (collect ((strings))
422     (let* ((pathname-directory (%pathname-directory pathname))
423     (defaults-directory (%pathname-directory defaults))
424     (prefix-len (length defaults-directory))
425     (result-dir
426     (cond ((and (> prefix-len 1)
427     (>= (length pathname-directory) prefix-len)
428     (compare-component (subseq pathname-directory
429     0 prefix-len)
430     defaults-directory))
431     ;; Pathname starts with a prefix of default. So just
432     ;; use a relative directory from then on out.
433     (cons :relative (nthcdr prefix-len pathname-directory)))
434     ((eq (car pathname-directory) :absolute)
435     ;; We are an absolute pathname, so we can just use it.
436     pathname-directory)
437     (t
438     ;; We are a relative directory. So we lose.
439     (lose)))))
440     (strings (unparse-unix-directory-list result-dir)))
441     (let* ((pathname-version (%pathname-version pathname))
442     (version-needed (and pathname-version
443     (not (eq pathname-version :newest))))
444     (pathname-type (%pathname-type pathname))
445     (type-needed (or version-needed
446     (and pathname-type
447     (not (eq pathname-type :unspecific)))))
448     (pathname-name (%pathname-name pathname))
449     (name-needed (or type-needed
450     (and pathname-name
451     (not (compare-component pathname-name
452     (%pathname-name
453     defaults)))))))
454     (when name-needed
455     (unless pathname-name (lose))
456     (strings (unparse-unix-piece pathname-name)))
457     (when type-needed
458     (when (or (null pathname-type) (eq pathname-type :unspecific))
459     (lose))
460     (strings ".")
461     (strings (unparse-unix-piece pathname-type)))
462     (when version-needed
463     (typecase pathname-version
464     ((member :wild)
465     (strings ".*"))
466     (integer
467     (strings (format nil ".~D" pathname-version)))
468     (t
469     (lose)))))
470     (apply #'concatenate 'simple-string (strings)))))
471 ram 1.1
472    
473 wlott 1.16 (defstruct (unix-host
474     (:include host
475     (:parse #'parse-unix-namestring)
476     (:unparse #'unparse-unix-namestring)
477     (:unparse-host #'unparse-unix-host)
478     (:unparse-directory #'unparse-unix-directory)
479     (:unparse-file #'unparse-unix-file)
480     (:unparse-enough #'unparse-unix-enough)
481     (:customary-case :lower))
482     (:make-load-form-fun make-unix-host-load-form))
483     )
484 ram 1.1
485 wlott 1.16 (defvar *unix-host* (make-unix-host))
486 ram 1.1
487 wlott 1.16 (defun make-unix-host-load-form (host)
488     (declare (ignore host))
489     '*unix-host*)
490 ram 1.1
491 wlott 1.16
492     ;;;; Wildcard matching stuff.
493 ram 1.1
494 wlott 1.16 (defmacro enumerate-matches ((var pathname &optional result
495     &key (verify-existance t))
496     &body body)
497     (let ((body-name (gensym)))
498     `(block nil
499     (flet ((,body-name (,var)
500     ,@body))
501     (%enumerate-matches (pathname ,pathname)
502     ,verify-existance
503     #',body-name)
504     ,result))))
505 ram 1.1
506 wlott 1.16 (defun %enumerate-matches (pathname verify-existance function)
507 ram 1.34 (when (pathname-type pathname)
508     (unless (pathname-name pathname)
509     (error "Cannot supply a type without a name:~% ~S" pathname)))
510     (when (and (integerp (pathname-version pathname))
511     (member (pathname-type pathname) '(nil :unspecific)))
512     (error "Cannot supply a version without a type:~% ~S" pathname))
513     (let ((directory (pathname-directory pathname)))
514     (if directory
515     (ecase (car directory)
516     (:absolute
517     (%enumerate-directories "/" (cdr directory) pathname
518     verify-existance function))
519     (:relative
520     (%enumerate-directories "" (cdr directory) pathname
521     verify-existance function)))
522     (%enumerate-files "" pathname verify-existance function))))
523 ram 1.1
524 wlott 1.16 (defun %enumerate-directories (head tail pathname verify-existance function)
525 ram 1.37 (declare (simple-string head))
526 wlott 1.16 (if tail
527     (let ((piece (car tail)))
528     (etypecase piece
529     (simple-string
530     (%enumerate-directories (concatenate 'string head piece "/")
531     (cdr tail) pathname verify-existance
532     function))
533 ram 1.36 ((or pattern (member :wild :wild-inferiors))
534 wlott 1.26 (let ((dir (unix:open-dir head)))
535 wlott 1.16 (when dir
536     (unwind-protect
537     (loop
538 wlott 1.26 (let ((name (unix:read-dir dir)))
539 wlott 1.16 (cond ((null name)
540     (return))
541     ((string= name "."))
542     ((string= name ".."))
543     ((pattern-matches piece name)
544     (let ((subdir (concatenate 'string
545     head name "/")))
546 wlott 1.26 (when (eq (unix:unix-file-kind subdir)
547 wlott 1.16 :directory)
548     (%enumerate-directories
549     subdir (cdr tail) pathname verify-existance
550     function)))))))
551 wlott 1.26 (unix:close-dir dir)))))
552 wlott 1.16 ((member :up)
553     (%enumerate-directories (concatenate 'string head "../")
554     (cdr tail) pathname verify-existance
555     function))))
556     (%enumerate-files head pathname verify-existance function)))
557 ram 1.1
558 wlott 1.16 (defun %enumerate-files (directory pathname verify-existance function)
559 ram 1.37 (declare (simple-string directory))
560 ram 1.36 (let ((name (%pathname-name pathname))
561     (type (%pathname-type pathname))
562     (version (%pathname-version pathname)))
563 ram 1.33 (cond ((member name '(nil :unspecific))
564 wlott 1.16 (when (or (not verify-existance)
565 wlott 1.26 (unix:unix-file-kind directory))
566 wlott 1.16 (funcall function directory)))
567     ((or (pattern-p name)
568     (pattern-p type)
569 ram 1.33 (eq name :wild)
570     (eq type :wild))
571 wlott 1.26 (let ((dir (unix:open-dir directory)))
572 wlott 1.16 (when dir
573     (unwind-protect
574     (loop
575 wlott 1.26 (let ((file (unix:read-dir dir)))
576 wlott 1.16 (if file
577 wlott 1.21 (unless (or (string= file ".")
578     (string= file ".."))
579     (multiple-value-bind
580     (file-name file-type file-version)
581     (let ((*ignore-wildcards* t))
582     (extract-name-type-and-version
583     file 0 (length file)))
584     (when (and (components-match file-name name)
585     (components-match file-type type)
586     (components-match file-version
587     version))
588     (funcall function
589     (concatenate 'string
590     directory
591     file)))))
592 wlott 1.16 (return))))
593 wlott 1.26 (unix:close-dir dir)))))
594 wlott 1.16 (t
595     (let ((file (concatenate 'string directory name)))
596 wlott 1.19 (unless (or (null type) (eq type :unspecific))
597 wlott 1.16 (setf file (concatenate 'string file "." type)))
598 ram 1.33 (unless (member version '(nil :newest :wild))
599 wlott 1.19 (setf file (concatenate 'string file "."
600 wlott 1.20 (quick-integer-to-string version))))
601 wlott 1.16 (when (or (not verify-existance)
602 ram 1.40 (unix:unix-file-kind file t))
603 wlott 1.16 (funcall function file)))))))
604 ram 1.1
605     (defun quick-integer-to-string (n)
606 wlott 1.16 (declare (type integer n))
607 ram 1.38 (cond ((not (fixnump n))
608     (write-to-string n :base 10 :radix nil))
609     ((zerop n) "0")
610 ram 1.1 ((eql n 1) "1")
611     ((minusp n)
612     (concatenate 'simple-string "-"
613     (the simple-string (quick-integer-to-string (- n)))))
614     (t
615     (do* ((len (1+ (truncate (integer-length n) 3)))
616     (res (make-string len))
617     (i (1- len) (1- i))
618     (q n)
619     (r 0))
620     ((zerop q)
621     (incf i)
622     (replace res res :start2 i :end2 len)
623 wlott 1.3 (shrink-vector res (- len i)))
624 ram 1.1 (declare (simple-string res)
625 ram 1.38 (fixnum len i r q))
626 ram 1.1 (multiple-value-setq (q r) (truncate q 10))
627     (setf (schar res i) (schar "0123456789" r))))))
628    
629 wlott 1.16
630     ;;;; UNIX-NAMESTRING -- public
631 wlott 1.5 ;;;
632 wlott 1.39 (defun unix-namestring (pathname &optional (for-input t) executable-only)
633 wlott 1.16 "Convert PATHNAME into a string that can be used with UNIX system calls.
634     Search-lists and wild-cards are expanded."
635 ram 1.41 ;; toy@rtp.ericsson.se: Let unix-namestring also handle logical
636     ;; pathnames too.
637     (let ((path (let ((lpn (pathname pathname)))
638     (if (logical-pathname-p lpn)
639     (namestring (translate-logical-pathname lpn))
640     pathname))))
641 wlott 1.16 (enumerate-search-list
642 ram 1.41 (pathname path)
643 wlott 1.16 (collect ((names))
644     (enumerate-matches (name pathname nil :verify-existance for-input)
645 wlott 1.39 (when (or (not executable-only)
646     (and (eq (unix:unix-file-kind name) :file)
647     (unix:unix-access name unix:x_ok)))
648     (names name)))
649 wlott 1.16 (let ((names (names)))
650     (when names
651     (when (cdr names)
652     (error "~S is ambiguous:~{~% ~A~}" pathname names))
653 ram 1.41 (return (car names))))))))
654 wlott 1.4
655 ram 1.1
656 wlott 1.16 ;;;; TRUENAME and PROBE-FILE.
657 ram 1.1
658     ;;; Truename -- Public
659     ;;;
660 wlott 1.4 ;;; Another silly file function trivially different from another function.
661 ram 1.1 ;;;
662     (defun truename (pathname)
663     "Return the pathname for the actual file described by the pathname
664 pw 1.47 An error of type file-error is signalled if no such file exists,
665     or the pathname is wild."
666     (if (wild-pathname-p pathname)
667     (error 'file-error
668     :format-control "Bad place for a wild pathname."
669     :pathname pathname)
670     (let ((result (probe-file pathname)))
671     (unless result
672     (error 'file-error
673     :pathname pathname
674     :format-control "The file ~S does not exist."
675     :format-arguments (list (namestring pathname))))
676     result)))
677 ram 1.1
678     ;;; Probe-File -- Public
679     ;;;
680 wlott 1.4 ;;; If PATHNAME exists, return it's truename, otherwise NIL.
681 ram 1.1 ;;;
682     (defun probe-file (pathname)
683     "Return a pathname which is the truename of the file if it exists, NIL
684 pw 1.47 otherwise. An error of type file-error is signaled if pathname is wild."
685     (if (wild-pathname-p pathname)
686     (error 'file-error
687     :pathname pathname
688     :format-control "Bad place for a wild pathname.")
689     (let ((namestring (unix-namestring pathname t)))
690     (when (and namestring (unix:unix-file-kind namestring))
691     (let ((truename (unix:unix-resolve-links
692     (unix:unix-maybe-prepend-current-directory
693     namestring))))
694     (when truename
695     (let ((*ignore-wildcards* t))
696     (pathname (unix:unix-simplify-pathname truename)))))))))
697 ram 1.1
698    
699 wlott 1.4 ;;;; Other random operations.
700 ram 1.1
701     ;;; Rename-File -- Public
702     ;;;
703     (defun rename-file (file new-name)
704     "Rename File to have the specified New-Name. If file is a stream open to a
705 ram 1.35 file, then the associated file is renamed."
706 wlott 1.4 (let* ((original (truename file))
707 wlott 1.16 (original-namestring (unix-namestring original t))
708 wlott 1.4 (new-name (merge-pathnames new-name original))
709     (new-namestring (unix-namestring new-name nil)))
710 wlott 1.17 (unless new-namestring
711 pw 1.47 (error 'file-error
712     :pathname new-name
713     :format-control "~S can't be created."
714     :format-arguments (list new-name)))
715 wlott 1.4 (multiple-value-bind (res error)
716 wlott 1.26 (unix:unix-rename original-namestring
717 wlott 1.4 new-namestring)
718     (unless res
719 pw 1.47 (error 'file-error
720     :pathname new-name
721     :format-control "Failed to rename ~A to ~A: ~A"
722     :format-arguments (list original new-name
723     (unix:get-unix-error-msg error))))
724 wlott 1.4 (when (streamp file)
725     (file-name file new-namestring))
726 wlott 1.16 (values new-name original (truename new-name)))))
727 ram 1.1
728     ;;; Delete-File -- Public
729     ;;;
730     ;;; Delete the file, Man.
731     ;;;
732     (defun delete-file (file)
733     "Delete the specified file."
734 wlott 1.4 (let ((namestring (unix-namestring file t)))
735 ram 1.1 (when (streamp file)
736     (close file :abort t))
737 ram 1.24 (unless namestring
738 pw 1.47 (error 'file-error
739     :pathname file
740     :format-control "~S doesn't exist."
741     :format-arguments (list file)))
742 ram 1.24
743 wlott 1.26 (multiple-value-bind (res err) (unix:unix-unlink namestring)
744 ram 1.24 (unless res
745 pw 1.47 (error 'file-error
746     :pathname namestring
747     :format-control "Could not delete ~A: ~A."
748     :format-arguments (list namestring
749     (unix:get-unix-error-msg err))))))
750 ram 1.1 t)
751 wlott 1.4
752 ram 1.1
753     ;;; User-Homedir-Pathname -- Public
754     ;;;
755 ram 1.12 ;;; Return Home:, which is set up for us at initialization time.
756 ram 1.1 ;;;
757     (defun user-homedir-pathname (&optional host)
758     "Returns the home directory of the logged in user as a pathname.
759 ram 1.12 This is obtained from the logical name \"home:\"."
760 ram 1.1 (declare (ignore host))
761 ram 1.12 #p"home:")
762 ram 1.1
763     ;;; File-Write-Date -- Public
764     ;;;
765     (defun file-write-date (file)
766 pw 1.47 "Return file's creation date, or NIL if it doesn't exist.
767     An error of type file-error is signaled if file is a wild pathname"
768     (if (wild-pathname-p file)
769     (error 'file-error
770     :pathname file
771     :format-control "Bad place for a wild pathname.")
772     (let ((name (unix-namestring file t)))
773     (when name
774     (multiple-value-bind
775     (res dev ino mode nlink uid gid rdev size atime mtime)
776     (unix:unix-stat name)
777     (declare (ignore dev ino mode nlink uid gid rdev size atime))
778     (when res
779     (+ unix-to-universal-time mtime)))))))
780 ram 1.1
781     ;;; File-Author -- Public
782     ;;;
783     (defun file-author (file)
784     "Returns the file author as a string, or nil if the author cannot be
785 pw 1.47 determined. Signals an error of type file-error if file doesn't exist,
786     or file is a wild pathname."
787     (if (wild-pathname-p file)
788     (error 'file-error
789     :pathname file
790     "Bad place for a wild pathname.")
791     (let ((name (unix-namestring (pathname file) t)))
792     (unless name
793     (error 'file-error
794     :pathname file
795     :format-control "~S doesn't exist."
796     :format-arguments (list file)))
797     (multiple-value-bind (winp dev ino mode nlink uid)
798     (unix:unix-stat name)
799     (declare (ignore dev ino mode nlink))
800     (if winp (lookup-login-name uid))))))
801 ram 1.1
802    
803     ;;;; DIRECTORY.
804    
805 wlott 1.4 ;;; DIRECTORY -- public.
806     ;;;
807 ram 1.23 (defun directory (pathname &key (all t) (check-for-subdirs t)
808     (follow-links t))
809 ram 1.1 "Returns a list of pathnames, one for each file that matches the given
810 ram 1.23 pathname. Supplying :ALL as nil causes this to ignore Unix dot files. This
811     never includes Unix dot and dot-dot in the result. If :FOLLOW-LINKS is NIL,
812     then symblolic links in the result are not expanded. This is not the
813     default because TRUENAME does follow links, and the result pathnames are
814     defined to be the TRUENAME of the pathname (the truename of a link may well
815     be in another directory.)"
816 wlott 1.16 (let ((results nil))
817     (enumerate-search-list
818 wlott 1.21 (pathname (merge-pathnames pathname
819     (make-pathname :name :wild
820     :type :wild
821     :version :wild)))
822 wlott 1.16 (enumerate-matches (name pathname)
823     (when (or all
824     (let ((slash (position #\/ name :from-end t)))
825     (or (null slash)
826     (= (1+ slash) (length name))
827     (char/= (schar name (1+ slash)) #\.))))
828     (push name results))))
829     (let ((*ignore-wildcards* t))
830     (mapcar #'(lambda (name)
831 ram 1.23 (let ((name (if (and check-for-subdirs
832 wlott 1.26 (eq (unix:unix-file-kind name)
833 ram 1.23 :directory))
834     (concatenate 'string name "/")
835     name)))
836     (if follow-links (truename name) (pathname name))))
837 wlott 1.16 (sort (delete-duplicates results :test #'string=) #'string<)))))
838 ram 1.1
839 wlott 1.4
840     ;;;; Printing directories.
841 ram 1.1
842     ;;; PRINT-DIRECTORY is exported from the EXTENSIONS package.
843     ;;;
844     (defun print-directory (pathname &optional stream &key all verbose return-list)
845     "Like Directory, but prints a terse, multi-coloumn directory listing
846     instead of returning a list of pathnames. When :all is supplied and
847     non-nil, then Unix dot files are included too (as ls -a). When :vervose
848     is supplied and non-nil, then a long listing of miscellaneous
849     information is output one file per line."
850 wlott 1.16 (let ((*standard-output* (out-synonym-of stream))
851     (pathname pathname))
852 ram 1.1 (if verbose
853     (print-directory-verbose pathname all return-list)
854     (print-directory-formatted pathname all return-list))))
855    
856     (defun print-directory-verbose (pathname all return-list)
857 ram 1.23 (let ((contents (directory pathname :all all :check-for-subdirs nil
858     :follow-links nil))
859 wlott 1.7 (result nil))
860     (format t "Directory of ~A :~%" (namestring pathname))
861     (dolist (file contents)
862     (let* ((namestring (unix-namestring file))
863     (tail (subseq namestring
864     (1+ (or (position #\/ namestring
865     :from-end t
866     :test #'char=)
867     -1)))))
868     (multiple-value-bind
869     (reslt dev-or-err ino mode nlink uid gid rdev size atime mtime)
870 wlott 1.26 (unix:unix-stat namestring)
871 wlott 1.7 (declare (ignore ino gid rdev atime)
872     (fixnum uid mode))
873     (cond (reslt
874     ;;
875     ;; Print characters for file modes.
876     (macrolet ((frob (bit name &optional sbit sname negate)
877     `(if ,(if negate
878     `(not (logbitp ,bit mode))
879     `(logbitp ,bit mode))
880     ,(if sbit
881     `(if (logbitp ,sbit mode)
882     (write-char ,sname)
883     (write-char ,name))
884     `(write-char ,name))
885     (write-char #\-))))
886     (frob 15 #\d nil nil t)
887     (frob 8 #\r)
888     (frob 7 #\w)
889     (frob 6 #\x 11 #\s)
890     (frob 5 #\r)
891     (frob 4 #\w)
892     (frob 3 #\x 10 #\s)
893     (frob 2 #\r)
894     (frob 1 #\w)
895     (frob 0 #\x))
896     ;;
897     ;; Print the rest.
898     (multiple-value-bind (sec min hour date month year)
899     (get-decoded-time)
900     (declare (ignore sec min hour date month))
901     (format t "~2D ~8A ~8D ~12A ~A~@[/~]~%"
902     nlink
903     (or (lookup-login-name uid) uid)
904     size
905     (decode-universal-time-for-files mtime year)
906     tail
907 wlott 1.27 (= (logand mode unix:s-ifmt) unix:s-ifdir))))
908 wlott 1.7 (t (format t "Couldn't stat ~A -- ~A.~%"
909     tail
910 wlott 1.26 (unix:get-unix-error-msg dev-or-err))))
911 ram 1.1 (when return-list
912 wlott 1.27 (push (if (= (logand mode unix:s-ifmt) unix:s-ifdir)
913 wlott 1.7 (pathname (concatenate 'string namestring "/"))
914     file)
915     result)))))
916     (nreverse result)))
917 ram 1.1
918     (defun decode-universal-time-for-files (time current-year)
919     (multiple-value-bind (sec min hour day month year)
920     (decode-universal-time (+ time unix-to-universal-time))
921     (declare (ignore sec))
922     (format nil "~A ~2,' D ~:[ ~D~;~*~2,'0D:~2,'0D~]"
923     (svref '#("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug"
924     "Sep" "Oct" "Nov" "Dec")
925     (1- month))
926     day (= current-year year) year hour min)))
927    
928     (defun print-directory-formatted (pathname all return-list)
929     (let ((width (or (line-length *standard-output*) 80))
930     (names ())
931     (cnt 0)
932     (max-len 0)
933 ram 1.23 (result (directory pathname :all all :follow-links nil)))
934 ram 1.1 (declare (list names) (fixnum max-len cnt))
935     ;;
936     ;; Get the data.
937 wlott 1.7 (dolist (file result)
938     (let* ((name (unix-namestring file))
939     (length (length name))
940     (end (if (and (plusp length)
941     (char= (schar name (1- length)) #\/))
942     (1- length)
943     length))
944     (slash-name (subseq name
945     (1+ (or (position #\/ name
946     :from-end t
947     :end end
948     :test #'char=)
949     -1))))
950     (len (length slash-name)))
951     (declare (simple-string slash-name)
952     (fixnum len))
953     (if (> len max-len) (setq max-len len))
954     (incf cnt)
955     (push slash-name names)))
956     (setq names (nreverse names))
957     ;;
958     ;; Do the output.
959     (let* ((col-width (1+ max-len))
960     (cols (max (truncate width col-width) 1))
961     (lines (ceiling cnt cols)))
962     (declare (fixnum cols lines))
963     (format t "Directory of ~A :~%" (namestring pathname))
964     (dotimes (i lines)
965     (declare (fixnum i))
966     (dotimes (j cols)
967     (declare (fixnum j))
968     (let ((name (nth (+ i (the fixnum (* j lines))) names)))
969     (when name
970     (write-string name)
971     (unless (eql j (1- cols))
972 wlott 1.15 (dotimes (i (- col-width (length (the simple-string name))))
973     (write-char #\space))))))
974 wlott 1.7 (terpri)))
975     (when return-list
976     result)))
977 ram 1.1
978    
979    
980     ;;;; Translating uid's and gid's.
981    
982     (defvar *uid-hash-table* (make-hash-table)
983     "Hash table for keeping track of uid's and login names.")
984    
985     ;;; LOOKUP-LOGIN-NAME translates a user id into a login name. Previous
986     ;;; lookups are cached in a hash table since groveling the passwd(s) files
987     ;;; is somewhat expensive. The table may hold nil for id's that cannot
988     ;;; be looked up since this means the files are searched in their entirety
989     ;;; each time this id is translated.
990     ;;;
991     (defun lookup-login-name (uid)
992     (multiple-value-bind (login-name foundp) (gethash uid *uid-hash-table*)
993     (if foundp
994     login-name
995     (setf (gethash uid *uid-hash-table*)
996     (get-group-or-user-name :user uid)))))
997    
998     (defvar *gid-hash-table* (make-hash-table)
999     "Hash table for keeping track of gid's and group names.")
1000    
1001     ;;; LOOKUP-GROUP-NAME translates a group id into a group name. Previous
1002     ;;; lookups are cached in a hash table since groveling the group(s) files
1003     ;;; is somewhat expensive. The table may hold nil for id's that cannot
1004     ;;; be looked up since this means the files are searched in their entirety
1005     ;;; each time this id is translated.
1006     ;;;
1007     (defun lookup-group-name (gid)
1008     (multiple-value-bind (group-name foundp) (gethash gid *gid-hash-table*)
1009     (if foundp
1010     group-name
1011     (setf (gethash gid *gid-hash-table*)
1012     (get-group-or-user-name :group gid)))))
1013    
1014    
1015     ;;; GET-GROUP-OR-USER-NAME first tries "/etc/passwd" ("/etc/group") since it is
1016     ;;; a much smaller file, contains all the local id's, and most uses probably
1017     ;;; involve id's on machines one would login into. Then if necessary, we look
1018     ;;; in "/etc/passwds" ("/etc/groups") which is really long and has to be
1019     ;;; fetched over the net.
1020     ;;;
1021     (defun get-group-or-user-name (group-or-user id)
1022     "Returns the simple-string user or group name of the user whose uid or gid
1023     is id, or NIL if no such user or group exists. Group-or-user is either
1024     :group or :user."
1025     (let ((id-string (let ((*print-base* 10)) (prin1-to-string id))))
1026     (declare (simple-string id-string))
1027     (multiple-value-bind (file1 file2)
1028     (ecase group-or-user
1029     (:group (values "/etc/group" "/etc/groups"))
1030     (:user (values "/etc/passwd" "/etc/passwd")))
1031     (or (get-group-or-user-name-aux id-string file1)
1032     (get-group-or-user-name-aux id-string file2)))))
1033    
1034     (defun get-group-or-user-name-aux (id-string passwd-file)
1035     (with-open-file (stream passwd-file)
1036     (loop
1037     (let ((entry (read-line stream nil)))
1038     (unless entry (return nil))
1039     (let ((name-end (position #\: (the simple-string entry)
1040     :test #'char=)))
1041     (when name-end
1042     (let ((id-start (position #\: (the simple-string entry)
1043     :start (1+ name-end) :test #'char=)))
1044     (when id-start
1045     (incf id-start)
1046     (let ((id-end (position #\: (the simple-string entry)
1047     :start id-start :test #'char=)))
1048     (when (and id-end
1049     (string= id-string entry
1050     :start2 id-start :end2 id-end))
1051     (return (subseq entry 0 name-end))))))))))))
1052    
1053    
1054 wlott 1.4 ;;;; File completion.
1055 ram 1.1
1056 chiles 1.13 ;;; COMPLETE-FILE -- Public
1057     ;;;
1058 wlott 1.4 (defun complete-file (pathname &key (defaults *default-pathname-defaults*)
1059     ignore-types)
1060 wlott 1.22 (let ((files (directory (complete-file-directory-arg pathname defaults)
1061 ram 1.23 :check-for-subdirs nil
1062     :follow-links nil)))
1063 wlott 1.4 (cond ((null files)
1064     (values nil nil))
1065     ((null (cdr files))
1066     (values (merge-pathnames (file-namestring (car files))
1067     pathname)
1068     t))
1069     (t
1070     (let ((good-files
1071     (delete-if #'(lambda (pathname)
1072 wlott 1.16 (and (simple-string-p
1073     (pathname-type pathname))
1074 wlott 1.4 (member (pathname-type pathname)
1075     ignore-types
1076     :test #'string=)))
1077     files)))
1078     (cond ((null good-files))
1079     ((null (cdr good-files))
1080     (return-from complete-file
1081     (values (merge-pathnames (file-namestring
1082     (car good-files))
1083     pathname)
1084     t)))
1085     (t
1086     (setf files good-files)))
1087     (let ((common (file-namestring (car files))))
1088     (dolist (file (cdr files))
1089     (let ((name (file-namestring file)))
1090     (dotimes (i (min (length common) (length name))
1091     (when (< (length name) (length common))
1092     (setf common name)))
1093     (unless (char= (schar common i) (schar name i))
1094     (setf common (subseq common 0 i))
1095     (return)))))
1096     (values (merge-pathnames common pathname)
1097     nil)))))))
1098 ram 1.1
1099 chiles 1.13 ;;; COMPLETE-FILE-DIRECTORY-ARG -- Internal.
1100     ;;;
1101     (defun complete-file-directory-arg (pathname defaults)
1102 wlott 1.22 (let* ((pathname (merge-pathnames pathname (directory-namestring defaults)))
1103 wlott 1.16 (type (pathname-type pathname)))
1104     (flet ((append-multi-char-wild (thing)
1105     (etypecase thing
1106     (null :wild)
1107     (pattern
1108     (make-pattern (append (pattern-pieces thing)
1109     (list :multi-char-wild))))
1110     (simple-string
1111     (make-pattern (list thing :multi-char-wild))))))
1112     (if (or (null type) (eq type :unspecific))
1113     ;; There is no type.
1114     (make-pathname :defaults pathname
1115     :name (append-multi-char-wild (pathname-name pathname))
1116     :type :wild)
1117     ;; There already is a type, so just extend it.
1118     (make-pathname :defaults pathname
1119     :name (pathname-name pathname)
1120     :type (append-multi-char-wild (pathname-type pathname)))))))
1121 chiles 1.13
1122 wlott 1.4 ;;; Ambiguous-Files -- Public
1123 ram 1.1 ;;;
1124 wlott 1.16 (defun ambiguous-files (pathname
1125     &optional (defaults *default-pathname-defaults*))
1126 wlott 1.4 "Return a list of all files which are possible completions of Pathname.
1127 chiles 1.13 We look in the directory specified by Defaults as well as looking down
1128     the search list."
1129 wlott 1.16 (directory (complete-file-directory-arg pathname defaults)
1130 ram 1.23 :follow-links nil
1131 wlott 1.16 :check-for-subdirs nil))
1132 wlott 1.4
1133 wlott 1.16
1134 ram 1.1
1135     ;;; File-writable -- exported from extensions.
1136     ;;;
1137     ;;; Determines whether the single argument (which should be a pathname)
1138 dtc 1.46 ;;; can be written by the current task.
1139 wlott 1.16 ;;;
1140 ram 1.1 (defun file-writable (name)
1141     "File-writable accepts a pathname and returns T if the current
1142     process can write it, and NIL otherwise."
1143 wlott 1.16 (let ((name (unix-namestring name nil)))
1144 wlott 1.17 (cond ((null name)
1145     nil)
1146 wlott 1.26 ((unix:unix-file-kind name)
1147     (values (unix:unix-access name unix:w_ok)))
1148 wlott 1.17 (t
1149     (values
1150 wlott 1.26 (unix:unix-access (subseq name
1151 wlott 1.17 0
1152     (or (position #\/ name :from-end t)
1153     0))
1154 wlott 1.26 (logior unix:w_ok unix:x_ok)))))))
1155 ram 1.1
1156    
1157     ;;; Pathname-Order -- Internal
1158     ;;;
1159     ;;; Predicate to order pathnames by. Goes by name.
1160     ;;;
1161     (defun pathname-order (x y)
1162     (let ((xn (%pathname-name x))
1163     (yn (%pathname-name y)))
1164     (if (and xn yn)
1165     (let ((res (string-lessp xn yn)))
1166     (cond ((not res) nil)
1167     ((= res (length (the simple-string xn))) t)
1168     ((= res (length (the simple-string yn))) nil)
1169     (t t)))
1170     xn)))
1171    
1172    
1173     ;;; Default-Directory -- Public
1174     ;;;
1175     (defun default-directory ()
1176     "Returns the pathname for the default directory. This is the place where
1177     a file will be written if no directory is specified. This may be changed
1178     with setf."
1179     (multiple-value-bind (gr dir-or-error)
1180 wlott 1.26 (unix:unix-current-directory)
1181 ram 1.1 (if gr
1182 wlott 1.16 (let ((*ignore-wildcards* t))
1183     (pathname (concatenate 'simple-string dir-or-error "/")))
1184 wlott 1.3 (error dir-or-error))))
1185 ram 1.1
1186     ;;; %Set-Default-Directory -- Internal
1187     ;;;
1188     (defun %set-default-directory (new-val)
1189 wlott 1.17 (let ((namestring (unix-namestring new-val t)))
1190     (unless namestring
1191     (error "~S doesn't exist." new-val))
1192     (multiple-value-bind (gr error)
1193 wlott 1.26 (unix:unix-chdir namestring)
1194 wlott 1.17 (if gr
1195     (setf (search-list "default:") (default-directory))
1196 wlott 1.26 (error (unix:get-unix-error-msg error))))
1197 wlott 1.17 new-val))
1198 wlott 1.16 ;;;
1199     (defsetf default-directory %set-default-directory)
1200    
1201     (defun filesys-init ()
1202     (setf *default-pathname-defaults*
1203     (%make-pathname *unix-host* nil nil nil nil :newest))
1204     (setf (search-list "default:") (default-directory))
1205     nil)
1206 dtc 1.42
1207     ;;; Ensure-Directories-Exist -- Public
1208     ;;;
1209     (defun ensure-directories-exist (pathspec &key verbose (mode #o777))
1210 pw 1.44 "Tests whether the directories containing the specified file
1211     actually exist, and attempts to create them if they do not.
1212     Portable programs should avoid using the :MODE keyword argument."
1213 dtc 1.43 (let* ((pathname (pathname pathspec))
1214     (pathname (if (logical-pathname-p pathname)
1215     (translate-logical-pathname pathname)
1216     pathname))
1217     (created-p nil))
1218     (when (wild-pathname-p pathname)
1219 pw 1.47 (error 'file-error
1220     :format-control "Bad place for a wild pathname."
1221     :pathname pathspec))
1222 dtc 1.45 (enumerate-search-list (pathname pathname)
1223     (let ((dir (pathname-directory pathname)))
1224     (loop for i from 1 upto (length dir)
1225     do (let ((newpath (make-pathname
1226     :host (pathname-host pathname)
1227     :device (pathname-device pathname)
1228     :directory (subseq dir 0 i))))
1229     (unless (probe-file newpath)
1230     (let ((namestring (namestring newpath)))
1231     (when verbose
1232     (format *standard-output* "~&Creating directory: ~A~%"
1233     namestring))
1234     (unix:unix-mkdir namestring mode)
1235     (unless (probe-file namestring)
1236 pw 1.47 (error 'file-error
1237     :pathname pathspec
1238     :format-control "Can't create directory ~A."
1239     :format-arguments (list namestring))))
1240 dtc 1.45 (setf created-p t)))))
1241     ;; Only the first path in a search-list is considered.
1242     (return (values pathname created-p))))))

  ViewVC Help
Powered by ViewVC 1.1.5