Debian Codegraph @

docs/index.html

raw
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <html>
3
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6 <title>CL-FAD - A portable pathname library for Common Lisp</title>
7 <style type="text/css">
8 pre { padding:5px; background-color:#e0e0e0 }
9 h3, h4, h5 { text-decoration: underline; }
10 a { text-decoration: none; padding: 1px 2px 1px 2px; }
11 a:visited { text-decoration: none; padding: 1px 2px 1px 2px; }
12 a:hover { text-decoration: none; padding: 1px 1px 1px 1px; border: 1px solid #000000; }
13 a:focus { text-decoration: none; padding: 1px 2px 1px 2px; border: none; }
14 a.none { text-decoration: none; padding: 0; }
15 a.none:visited { text-decoration: none; padding: 0; }
16 a.none:hover { text-decoration: none; border: none; padding: 0; }
17 a.none:focus { text-decoration: none; border: none; padding: 0; }
18 a.noborder { text-decoration: none; padding: 0; }
19 a.noborder:visited { text-decoration: none; padding: 0; }
20 a.noborder:hover { text-decoration: none; border: none; padding: 0; }
21 a.noborder:focus { text-decoration: none; border: none; padding: 0; }
22 pre.none { padding:5px; background-color:#ffffff }
23 </style>
24 </head>
25
26 <body bgcolor=white>
27
28 <h2>CL-FAD - A portable pathname library for Common Lisp</h2>
29
30 <blockquote>
31 <br>&nbsp;<br><h3><a name=abstract class=none>Abstract</a></h3>
32
33 CL-FAD (for "<font color=red>F</font>iles <font color=red>a</font>nd
34 <font color=red>D</font>irectories") is a thin layer atop Common
35 Lisp's standard pathname functions. It is intended to provide some
36 unification between current CL implementations on Windows, OS X,
37 Linux, and Unix. Most of the code was written by Peter Seibel for his book <a href="http://www.gigamonkeys.com/book/"><em>Practical Common Lisp</em></a>.
38
39 <p>
40
41 CL-FAD comes with a <a
42 href="http://www.opensource.org/licenses/bsd-license.php">BSD-style
43 license</a> so you can basically do with it whatever you want.
44
45 <p>
46 <font color=red>Download shortcut:</font> <a href="http://weitz.de/files/cl-fad.tar.gz">http://weitz.de/files/cl-fad.tar.gz</a>.
47 </blockquote>
48
49 <br>&nbsp;<br><h3><a class=none name="contents">Contents</a></h3>
50 <ol>
51 <li><a href="#download">Download and installation</a>
52 <li><a href="#implementations">Supported Lisp implementations</a>
53 <li><a href="#dictionary">The CL-FAD dictionary</a>
54 <ol>
55 <li><a href="#querying">Querying files, directories and pathnames</a>
56 <ol>
57 <li><a href="#directory-exists-p"><code>directory-exists-p</code> [function]</a>
58 <li><a href="#directory-pathname-p"><code>directory-pathname-p</code> [function]</a>
59 <li><a href="#file-exists-p"><code>file-exists-p</code> [function]</a>
60 <li><a href="#pathname-absolute-p"><code>pathname-absolute-p</code> [function]</a>
61 <li><a href="#pathname-equal"><code>pathname-equal</code> [function]</a>
62 <li><a href="#pathname-relative-p"><code>pathname-relative-p</code> [function]</a>
63 <li><a href="#pathname-root-p"><code>pathname-root-p</code> [function]</a>
64 </ol> </li>
65 <li><a href="#manipulating">Manipulating pathnames</a>
66 <ol>
67 <li><a href="#canonical-pathname"><code>canonical-pathname</code> [function]</a>
68 <li><a href="#merge-pathnames-as-directory"><code>merge-pathnames-as-directory</code> [function]</a>
69 <li><a href="#merge-pathnames-as-file"><code>merge-pathnames-as-file</code> [function]</a>
70 <li><a href="#pathname-as-directory"><code>pathname-as-directory</code> [function]</a>
71 <li><a href="#pathname-as-file"><code>pathname-as-file</code> [function]</a>
72 <li><a href="#pathname-directory-pathname"><code>pathname-directory-pathname</code> [function]</a>
73 <li><a href="#pathname-parent-directory"><code>pathname-parent-directory</code> [function]</a>
74 </ol> </li>
75 <li><a href="#traversing">Traversing directories</a>
76 <ol>
77 <li><a href="#list-directory"><code>list-directory</code> [function]</a>
78 <li><a href="#walk-directory"><code>walk-directory</code> [function]</a>
79 </ol> </li>
80 <li><a href="#temporary-files">Temporary Files</a>
81 <ol>
82 <li><a href="#open-temporary"><code>open-temporary</code> [function]</a>
83 <li><a href="#with-output-to-temporary-file"><code>with-output-to-temporary-file</code> [macro]</a>
84 <li><a href="#with-open-temporary-file"><code>with-open-temporary-file</code> [macro]</a>
85 <li><a href="#star-default-template-star"><code>*default-template*</code> [variable]</a>
86 <li><a href="#cannot-create-temporary-file"><code>cannot-create-temporary-file</code> [condition]</a>
87 <li><a href="#invalid-temporary-pathname-template"><code>invalid-temporary-pathname-template</code> [condition]</a>
88 <li><a href="#missing-temp-environment-variable"><code>missing-temp-environment-variable</code> [condition]</a>
89 <li><a href="#lp-host-temporary-files"><code>temporary-files</code> [logical pathname host]</a>
90 </ol>
91 </li>
92 <li><a href="#modifying">Modifying the file system</a>
93 <ol>
94 <li><a href="#copy-file"><code>copy-file</code> [function]</a>
95 <li><a href="#copy-stream"><code>copy-stream</code> [function]</a>
96 <li><a href="#delete-directory-and-files"><code>delete-directory-and-files</code> [function]</a>
97 </ol> </li>
98 <li><a href="#package-path"><code>path</code> [package]</a>
99 </ol>
100 <li><a href="#ack">Acknowledgements</a>
101 </ol>
102
103
104
105 <br>&nbsp;<br><h3><a class=none name="download">Download and installation</a></h3>
106
107 CL-FAD together with this documentation can be downloaded from <a
108 href="https://github.com/edicl/cl-fad/releases/latest">https://github.com/edicl/cl-fad/releases/latest</a>. The
109 current version is 0.7.6.
110 <p>
111 CL-FAD comes with simple system definitions for <a
112 href="http://www.cliki.net/mk-defsystem">MK:DEFSYSTEM</a> and <a
113 href="http://www.cliki.net/asdf">asdf</a> so you can either adapt it
114 to your needs or just unpack the archive and from within the CL-FAD
115 directory start your Lisp image and evaluate the form
116 <code>(mk:compile-system&nbsp;&quot;cl-fad&quot;)</code> - or <code>(asdf:oos&nbsp;'asdf:load-op&nbsp;:cl-fad)</code> for asdf - which should compile and load the whole
117 system.
118 Installation via <a
119 href="http://www.cliki.net/asdf-install">asdf-install</a> should as well
120 be possible. Plus, there are ports
121 for <a href="http://www.gentoo.org/proj/en/common-lisp/index.xml">Gentoo Linux</a> thanks to Matthew Kennedy
122 and for <a href="http://packages.debian.org/cgi-bin/search_packages.pl?keywords=cl-fad&amp;searchon=names&amp;subword=1&amp;version=all&amp;release=all">Debian Linux</a> thanks to Ren&eacute; van Bevern.
123 <p>
124 If for some reason you can't or don't want to use MK:DEFSYSTEM or asdf you
125 can just <code>LOAD</code> the file <code>load.lisp</code>.
126 <p>
127 The latest version of the source code lives in the github repository <a href="https://github.com/edicl/cl-fad">edicl/cl-fad</a>.
128
129 If you want to send patches,
130 please <a href="http://weitz.de/patches.html">read this first</a>.
131 Please submit your changes
132 as <a href="https://github.com/edicl/cl-fad/pulls">GitHub pull
133 request"</a>.
134
135 <br>&nbsp;<br><h3><a class=none name="implementations">Supported Lisp implementations</a></h3>
136
137 <p>
138 The following Common Lisp implementations are currently supported:
139 <ul>
140 <li><a href="http://armedbear.org/abcl.html">Armed Bear Common Lisp</a>
141 <li><a href="http://www.cons.org/cmucl/">CMUCL</a>
142 <li><a href="http://www.cormanlisp.com/">Corman Common Lisp</a>
143 <li><a href="http://ecls.sf.net/">ECL</a>
144 <li><a href="http://www.franz.com/products/allegrocl/">Franz AllegroCL</a>
145 <li><a href="http://clisp.cons.org/">GNU CLISP</a>
146 <li><a href="http://www.lispworks.com/">LispWorks</a>
147 <li><a href="http://www.digitool.com/">Macintosh Common Lisp</a>
148 <li><a href="http://openmcl.clozure.com/">OpenMCL</a>
149 <li><a href="http://www.scieneer.com/scl/">Scieneer Common Lisp</a>
150 <li><a href="http://sbcl.sourceforge.net/">Steel Bank Common Lisp</a>
151 </ul>
152
153 I'll gladly accepts patches to make CL-FAD work on other platforms.
154
155
156 <br>&nbsp;<br><h3><a class=none name="dictionary">The CL-FAD dictionary</a></h3>
157
158 <h4><a class=none name="querying">Querying files, directories and pathnames</a></h4>
159
160 <p><br>[Function]
161 <br><a class=none name="directory-exists-p"><b>directory-exists-p</b> <i> pathspec </i> =&gt; <i> generalized-boolean</i></a>
162
163 <blockquote><br>
164 Checks whether the file named by the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname_designator">pathname designator</a> <code><i>pathspec</i></code>
165 exists and if it is a directory. Returns its <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_t.htm#truename">truename</a> if this is the
166 case, <code>NIL</code> otherwise. The truename is returned in <em>directory form</em> as if
167 by <a href="#pathname-as-directory"><code>PATHNAME-AS-DIRECTORY</code></a>.
168 </blockquote>
169
170 <p><br>[Function]
171 <br><a class=none name="directory-pathname-p"><b>directory-pathname-p</b> <i> pathspec </i> =&gt; <i> generalized-boolean</i></a>
172
173 <blockquote><br>
174 Returns <code>NIL</code> if <code><i>pathspec</i></code> (a <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname_designator">pathname designator</a>) does not designate
175 a directory, <code><i>pathspec</i></code> otherwise. It is irrelevant whether the file or
176 directory designated by <code><i>pathspec</i></code> does actually exist.
177 </blockquote>
178
179 <p><br>[Function]
180 <br><a class=none name="file-exists-p"><b>file-exists-p</b> <i> pathspec </i> =&gt; <i> generalized-boolean</i></a>
181
182 <blockquote><br>
183 Checks whether the file named by the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname_designator">pathname designator</a> <code><i>pathspec</i></code>
184 exists and returns its <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_t.htm#truename">truename</a> if this is the case, <code>NIL</code> otherwise.
185 The truename is returned in "canonical" form, i.e. the truename of a
186 directory is returned in <em>directory form</em> as if by <a href="#pathname-as-directory"><code>PATHNAME-AS-DIRECTORY</code></a>.
187 </blockquote>
188
189 <p><br>[Function]<br><a class=none name='pathname-absolute-p'><b>pathname-absolute-p</b> <i>a</i> =&gt; <i>result</i></a>
190 <blockquote>
191 <p>Returns true if <code><i>a</i></code> is an absolute pathname. This simply
192 tests if <code><i>a</i></code>&#039;s directory list starts with <code>:ABSOLUTE</code></p>
193 </blockquote>
194
195 <p><br>[Function]<br><a class=none name='pathname-equal'><b>pathname-equal</b> <i>a b</i> =&gt; <i>result</i></a>
196 <blockquote>
197
198 <p>Returns <em>true</em> if <code><i>a</i></code> and <code><i>b</i></code>
199 represent the same pathname. This function does not access the
200 filesystem, it only looks at the components of the two pathnames to
201 test if they are the same (though by passing both <code><i>a</i></code>
202 and <code><i>b</i></code> to probe-file one can make this function test for
203 file &#039;sameness&#039;.</p>
204
205 <p>Equality is defined as:</p>
206
207 <ul>
208 <li>strings that are <code>string=</code>
209 <li>symbols (including <code>nil</code> and keywords) which are <code>eql</code>
210 <li>lists of the same length with equal (as per these rules) elements.
211 </ul>
212
213 <p>If any of these tree conditions is false for any of the components in
214 <code><i>a</i></code> and <code><i>b</i></code> then <code><i>a</i></code>
215 and <code><i>b</i></code> are different, otherwise they are the same.</p>
216
217 <p><em>NB:</em> This function does not convert name strings to pathnames. So
218 &quot;foo.txt&quot; and #P&quot;foo.txt&quot; are different pathnames.</p>
219
220 </blockquote>
221
222 <p><br>[Function]<br><a class=none name='pathname-relative-p'><b>pathname-relative-p</b> <i>a</i> =&gt; <i>result</i></a>
223 <blockquote>
224 <p>Returns true if <code><i>a</i></code> is a relative pathname. This simply
225 tests if <code><i>a</i></code>&#039;s directory starts
226 with <code>:RELATIVE</code>.</p>
227 </blockquote>
228
229 <p><br>[Function]<br><a class=none name='pathname-root-p'><b>pathname-root-p</b> <i>a</i> =&gt; <i>result</i></a>
230 <blockquote>
231 <p>Returns <em>true</em> if <code><i>pathname</i></code> is the root
232 directory (in other words, a directory which is its own parent).</p>
233 </blockquote>
234
235 <h4><a class=none name="manipulating">Manipulating pathnames</a></h4>
236
237 <p><br>[Function]<br><a class=none name='canonical-pathname'><b>canonical-pathname</b> <i>pathname</i> =&gt; <i>result</i></a>
238 <blockquote>
239 <p>Remove redundant information from PATHNAME.</p>
240
241 <p>This simply walks down <code>PATHNAME</code>&#039;s
242 pathname-directory and drops &quot;.&quot; directories, removes :back
243 and its preceding element.</p>
244
245 <p>NB: This function does not access the filesystem, it only looks at the
246 values in the pathname and works on their known (or assumed)
247 meanings.</p>
248
249 <p>NB: Since this function does not access the filesystem it will only
250 remove <code>:BACK</code> elements from the path (not <code>:UP</code>
251 elements). Since some lisps, ccl/sbcl/clisp convert &quot;..&quot; in
252 pathnames to <code>:UP</code>, and not <code>:BACK</code>, the actual
253 utility of the function is limited.</p>
254 </blockquote>
255
256 <p><br>[Function]<br><a class=none name='merge-pathnames-as-directory'><b>merge-pathnames-as-directory</b> <i><tt>&amp;rest</tt> pathnames</i> =&gt; <i>result</i></a>
257 <blockquote>
258 <p>Given a list of (probably relative) pathnames, this returns a single
259 directory pathname containing the logical concatenation of them all.</p>
260
261 <p>The returned value is the current directory if one were to cd into
262 each of <code><i>pathnames</i></code> in order. For this reason an
263 absolute pathname will, effectively, cancel the effect of any previous
264 relative pathnames.</p>
265
266 <p>The returned value&#039;s defaults are taken from the first element of
267 <code><i>pathnames</i></code> (host, version and device).</p>
268
269 <p><em>NB:</em> Since this function only looks at directory names the name and
270 type of the elements of <code><i>pathnames</i></code> are ignored. Make sure to properly
271 use either trailing #\/s, or <a href="#pathname-as-directory">pathname-as-directory</a>, to get the
272 expected results.</p>
273
274 <p>Examples:</p>
275
276 <pre>
277 (merge-pathnames-as-directory #P&quot;foo/&quot; #P&quot;bar/&quot;) == #P&quot;foo/bar/&quot;
278
279 (merge-pathnames-as-directory #P&quot;foo/&quot; #P&quot;./bar/&quot;) == #P&quot;foo/./bar/&quot;
280
281 (merge-pathnames-as-directory #P&quot;foo/&quot; #P&quot;/bar/&quot;) == #P&quot;/bar/&quot;
282
283 (merge-pathnames-as-directory #P&quot;foo/&quot; #P&quot;/bar/&quot; #P&#039;quux/file.txt) == #P&quot;/bar/quux/&quot;
284 </pre>
285
286 </blockquote>
287
288 <p><br>[Function]<br><a class=none name='merge-pathnames-as-file'><b>merge-pathnames-as-file</b> <i><tt>&amp;rest</tt> pathnames</i> =&gt; <i>result</i></a>
289 <blockquote>
290 <p>Given a list of, probably relative, pathnames returns a single
291 filename pathname containing the logical concatenation of them all.</p>
292
293 <p>The returned value&#039;s defaults are taken from the first element of
294 <code><i>pathnames</i></code> (host, version and device). The returned
295 values&#039;s name, type and version are taken from the last element
296 of <code><i>pathnames</i></code>. The intervening elements are used only for
297 their pathname-directory values.</p>
298
299 Examples:
300
301 <pre>
302 (merge-pathnames-as-file #P&quot;foo/&quot; #P&quot;bar.txt&quot;) == #P&quot;foo/bar.txt&quot;
303
304 (merge-pathnames-as-file #P&quot;foo/&quot; #P&quot;./bar.txt&quot;) == #P&quot;foo/./bar.txt&quot;
305
306 (merge-pathnames-as-file #P&quot;foo/&quot; #P&quot;/bar/README&quot;) == #P&quot;/bar/README&quot;
307
308 (merge-pathnames-as-file #P&quot;/foo/&quot; #P&quot;/bar/&quot; #P&#039;quux/file.txt) == #P&quot;/bar/quux/file.txt&quot;
309 </pre>
310
311 </blockquote>
312
313 <p><br>[Function]
314 <br><a class=none name="pathname-as-directory"><b>pathname-as-directory</b> <i> pathspec </i> =&gt; <i> pathname</i></a>
315 <blockquote><br>
316 Converts the <em>non-wild</em> <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname_designator">pathname designator</a> <code><i>pathspec</i></code> to <em>directory form</em>, i.e. it returns a <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname">pathname</a> which would return a <em>true</em> value if fed to <a href="#directory-pathname-p"><code>DIRECTORY-PATHNAME-P</code></a>.
317 </blockquote>
318
319 <p><br>[Function]
320 <br><a class=none name="pathname-as-file"><b>pathname-as-file</b> <i> pathspec </i> =&gt; <i> pathname</i></a>
321
322 <blockquote><br>
323 Converts the <em>non-wild</em> <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname_designator">pathname designator</a> <code><i>pathspec</i></code> to <em>file form</em>, i.e. it returns a <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname">pathname</a> which would return a <code>NIL</code> value if fed to <a href="#directory-pathname-p"><code>DIRECTORY-PATHNAME-P</code></a>.
324 </blockquote>
325
326 <p><br>[Function]<br><a class=none name='pathname-directory-pathname'><b>pathname-directory-pathname</b> <i>pathname</i> =&gt; <i>result</i></a>
327 <blockquote>
328 <p>Returns a complete pathname representing the directory of
329 <code><i>pathname</i></code>. If <code><i>pathname</i></code> is
330 already a directory pathname
331 (<code>name</code> <code>nil</code>, <code>type</code>
332 <code>nil</code>) returns a pathname equal (as
333 per <a href="#pathname-equal">pathname-equal</a>) to it.</p>
334 </blockquote>
335
336 <p><br>[Function]<br><a class=none name='pathname-parent-directory'><b>pathname-parent-directory</b> <i>pathname</i> =&gt; <i>result</i></a>
337 <blockquote>
338
339 <p>Returns a pathname which would, by name at least,
340 contain <code><i>pathname</i></code> as one of its direct
341 children. Symlinks can make the parent/child relationship a like
342 opaque, but generally speaking the value returned by this function is
343 a directory name which contains <code><i>pathname</i></code>.</p>
344
345 <p>The root directory, #P&quot;/&quot;, is its own parent. The parent
346 directory of a filename is the parent of the filename&#039;s
347 dirname.</p>
348
349 </blockquote>
350
351 <h4><a class=none name="traversing">Traversing directories</a></h4>
352
353 <p><br>[Function]
354 <br><a class=none name="list-directory"><b>list-directory</b> <i> dirname <tt>&amp;key</tt> follow-symlinks</i> =&gt; <i> list</i></a>
355
356 <blockquote><br>
357 <p>
358 Returns a <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#fresh">fresh</a> list of pathnames corresponding to
359 all files within the directory named by the non-wild <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname_designator">pathname designator</a> <code><i>dirname</i></code>. The pathnames of sub-directories are returned in
360 <em>directory form</em> - see <a href="#pathname-as-directory"><code>PATHNAME-AS-DIRECTORY</code></a>.
361 </p>
362 <p>
363 If <code><i>follow-symlinks</i></code> is true (which is the
364 default), then the returned list contains truenames (symlinks will
365 be resolved) which essentially means that it might also return files
366 from <b>outside</b> the directory. This works on all platforms.
367 </p>
368 <p>
369 When <code><i>follow-symlinks</i></code> is <code>NIL</code>, it should return the actual directory
370 contents, which might include symlinks. (This is currently implemented only on SBCL and CCL.)
371 </p>
372 </blockquote>
373
374 <p><br>[Function]
375 <br><a class=none name="walk-directory"><b>walk-directory</b> <i> dirname fn <tt>&amp;key</tt> directories if-does-not-exist test follow-symlinks</i> =&gt; |</a>
376
377 <blockquote><br>
378 <p>
379 Recursively applies the function designated by the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#function_designator">function
380 designator</a> <code><i>fn</i></code> to all files within the directory named
381 by the non-wild <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname_designator">pathname
382 designator</a> <code><i>dirname</i></code> and all of its sub-directories. <code><i>fn</i></code>
383 will only be applied to files for which the function <code><i>test</i></code>
384 returns a <em>true</em> value. (The default value for <code><i>test</i></code>
385 always returns <em>true</em>.) If <code><i>directories</i></code> is not <code>NIL</code>,
386 <code><i>fn</i></code> and <code><i>test</i></code> are applied to directories
387 as well. If <code><i>directories</i></code> is <code>:DEPTH-FIRST</code>, <code><i>fn</i></code>
388 will be applied to the directory's contents first. If <code><i>directories</i></code>
389 is <code>:BREADTH-FIRST</code> and <code><i>test</i></code> returns <code>NIL</code>, the
390 directory's content will be skipped. <code><i>if-does-not-exist</i></code> must
391 be one of <code>:ERROR</code> or <code>:IGNORE</code> where <code>:ERROR</code>
392 (the default) means that an error will be signaled if the directory <code><i>dirname</i></code>
393 does not exist.
394 </p>
395 <p>
396 If <code><i>follow-symlinks</i></code> is true (which is
397 the default), then your callback will receive truenames. Otherwise
398 you should get the actual directory contents, which might include
399 symlinks. This might not be supported on all platforms. See
400 <a href="#list-directory"><code>LIST-DIRECTORY</code></a>.
401 </p>
402 </blockquote>
403
404 <h4><a class=none name="temporary-files">Temporary Files</a></h4>
405
406 <h5>Synopsis</h5>
407
408 <p>
409 Create a temporary file and return its name:
410 <pre>CL-USER&gt; (temporary-file:<code xmlns=""><a href="#with-output-to-temporary-file">with-output-to-temporary-file</a></code> (foo)
411 (print "hello" foo))
412 #P"/var/folders/Yu/YuNMNBNPGoqs9G-1Wmj1dk+++TI/-Tmp-/temp-yjck024x"</pre>
413 </p>
414 <p>
415 Create a temporary file, read and write it, have it be deleted
416 automatically:
417 <pre>CL-USER&gt; (temporary-file:<code xmlns=""><a href="#with-open-temporary-file">with-open-temporary-file</a></code> (foo :direction :io)
418 (print "hello" foo)
419 (file-position foo 0)
420 (read foo))
421 "hello"</pre>
422 </p>
423
424 <h5><a class="none" name="default-temporary-directory">Default temporary file directory</a></h5>
425 By default, temporary files are created in a system specific
426 directory that defaults based on operating system conventions. On
427 Unix and Unix-like systems, the directory <tt>/tmp/</tt> is used
428 by default. It can be overridden by setting the <tt>TMPDIR</tt>
429 environment variable. On Windows, the value of the environment
430 variable <tt>TEMP</tt> is used. If it is not set, temporary file
431 creation will fail.
432
433 <h5><a class="none" name="defining-temporary-directory">Defining the temporary file directory</a></h5>
434 <p>
435 The Lisp application can set the default directory in which
436 temporary files are created by the way of the
437 <code xmlns=""><a href="#temporary-files">temporary-files</a></code> logical pathname host:
438
439 <pre>(setf (<a xmlns="" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_logica.htm">logical-pathname-translations</a> "<code xmlns=""><a href="#temporary-files">temporary-files</a></code>") '(("*.*.*" "/var/tmp/")))</pre>
440
441 This would set the directory for temporary files to
442 <tt>/var/tmp/</tt>. For more information about logical
443 pathnames, please refer to <a href="http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/html/cltl/clm/node208.html#SECTION002715000000000000000">Common
444 Lisp the Language, 2nd Edition</a> and the <a href="http://clhs.lisp.se/Body/19_.htm">Common Lisp
445 HyperSpec</a>.
446 </p>
447 <p>
448 Physical path names have restrictions regarding the permitted
449 character in file names. If these restrictions conflict with
450 your desired naming scheme, you can pass a physical pathname as
451 TEMPLATE parameter to the temporary file generation function.
452 </p>
453 <p>
454 Here are a few examples:
455 <pre>CL-USER&gt; (<a xmlns="" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_logica.htm">logical-pathname-translations</a> "temporary-files")
456 (("*.*.*" #P"/var/folders/Yu/YuNMNBNPGoqs9G-1Wmj1dk+++TI/-Tmp-/"))
457 CL-USER&gt; (temporary-file:<code xmlns=""><a href="#with-open-temporary-file">with-open-temporary-file</a></code> (foo)
458 (<a xmlns="" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn.htm">pathname</a> foo))
459 #P"/var/folders/Yu/YuNMNBNPGoqs9G-1Wmj1dk+++TI/-Tmp-/temp-6rdqdkd1"</pre>
460
461 This used the temporary directory established in the TMPDIR
462 environment variable, by the way of the definition of the
463 temporary-files logical host definition.
464
465 <pre>CL-USER&gt; (temporary-file:<code xmlns=""><a href="#with-open-temporary-file">with-open-temporary-file</a></code> (foo :template "/tmp/file.with.dots.in.name.%.txt")
466 (<a xmlns="" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn.htm">pathname</a> foo))
467 #P"/tmp/file.with.dots.in.name.2EF04KUJ.txt"</pre>
468
469 Here, a physical pathname was used for the
470 <code xmlns=""><i>:template</i></code> keyword argument so that a
471 filename containing multiple dots could be generated.
472
473 <pre>CL-USER&gt; (temporary-file:<code xmlns=""><a href="#with-open-temporary-file">with-open-temporary-file</a></code> (foo :template "temporary-files:blah-%.txt")
474 (<a xmlns="" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn.htm">pathname</a> foo))
475 #P"/var/folders/Yu/YuNMNBNPGoqs9G-1Wmj1dk+++TI/-Tmp-/blah-72mj450d.txt"</pre>
476
477 This used the temporary-files logical pathname host, but changed
478 the filename slightly.
479
480 <pre>CL-USER&gt; *default-pathname-defaults*
481 #P"/Users/hans/"
482 CL-USER&gt; (temporary-file:<code xmlns=""><a href="#with-open-temporary-file">with-open-temporary-file</a></code> (foo :template "blah-%.txt")
483 (<a xmlns="" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn.htm">pathname</a> foo))
484 #P"/Users/hans/blah-5OEJELG2.txt"</pre>
485
486 Here, a relative pathname was used in the template, which
487 caused the file to be generated in the directory established
488 by <a xmlns="" href="http://www.lispworks.com/documentation/HyperSpec/Body/v_defaul.htm">*default-pathname-defaults*</a>.
489 </p>
490 <p>
491 Alternatively, the <code xmlns=""><a href="#*default-template*">*default-template*</a></code>
492 special variable can be set to define a custom default template
493 for generating names.
494 </p>
495
496 <h5 xmlns=""><a class="none" name="security">Security</a></h5>
497 The TEMPORARY-FILE library does not directly address security
498 issues. The application that uses it needs to take additional
499 measures if it is important that files created by one process
500 cannot be accessed by other, unrelated processes. This can be
501 done by using the system dependent security mechanisms like
502 default file permissions or access control lists.
503
504 <h5>Dictionary</h5>
505
506
507 <p xmlns="">[Function]<br><a class="none" name="open-temporary"><b>open-temporary</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc"><tt>&amp;rest</tt> open-arguments <tt>&amp;key</tt> template generate-random-string max-tries <tt>&amp;allow-other-keys</tt></clix:lambda-list></i>
508 =&gt;
509 <i>stream</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
510 <p xmlns="http://www.w3.org/1999/xhtml">
511 Create a file with a randomly generated name and return the
512 opened stream. The resulting pathname is generated from
513 <code xmlns=""><i>template</i></code>, which is a string
514 representing a pathname template. A percent sign (%) in
515 that string is replaced by a randomly generated string to
516 make the filename unique. The default for
517 <code xmlns=""><i>template</i></code> places temporary files in the
518 <code xmlns=""><a href="#temporary-files">temporary-files</a></code> logical pathname host,
519 which is automatically set up in a system specific manner.
520 The file name generated from <code xmlns=""><i>template</i></code>
521 is merged with <a xmlns="" href="http://www.lispworks.com/documentation/HyperSpec/Body/v_defaul.htm">*default-pathname-defaults*</a>,
522 so random pathnames relative to that directory can be
523 generated by not specifying a directory in
524 <code xmlns=""><i>template</i></code>.
525 </p>
526 <p xmlns="http://www.w3.org/1999/xhtml">
527 <code xmlns=""><i>generate-random-string</i></code> can be passed to
528 override the default function that generates the random name
529 component. It should return a random string consisting of
530 characters that are permitted in a pathname (logical or
531 physical, depending on <code xmlns=""><i>template</i></code>).
532 </p>
533 <p xmlns="http://www.w3.org/1999/xhtml">
534 The name of the temporary file can be accessed calling the
535 <a xmlns="" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_pn.htm">pathname</a>
536 function on <code xmlns=""><i>stream</i></code>. For convenience,
537 the temporary file is opened on the physical pathname,
538 i.e. if the <code xmlns=""><i>template</i></code> designate a
539 logical pathname the translation to a physical pathname is
540 performed before opening the stream.
541 </p>
542 <p xmlns="http://www.w3.org/1999/xhtml">
543 In order to create a unique file name,
544 <code xmlns=""><a href="#open-temporary">open-temporary</a></code> may loop internally up
545 to <code xmlns=""><i>max-tries</i></code> times before giving up and
546 signalling a
547 <code xmlns=""><a href="#cannot-create-temporary-file">cannot-create-temporary-file</a></code> condition.
548 </p>
549 <p xmlns="http://www.w3.org/1999/xhtml">
550 Any unrecognized keyword arguments are passed to the call to
551 <a xmlns="" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_open.htm">open</a>.
552 </p>
553 </clix:description></blockquote></p>
554 <p xmlns="">[Macro]<br><a class="none" name="with-output-to-temporary-file"><b>with-output-to-temporary-file</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">(stream <tt>&amp;rest</tt> args) <tt>&amp;body</tt> body</clix:lambda-list></i>
555 =&gt;
556 <i>pathname</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
557 Create a temporary file using
558 <code xmlns=""><a href="#open-temporary">open-temporary</a></code> with
559 <code xmlns=""><i>args</i></code> and run <code xmlns=""><i>body</i></code>
560 with <code xmlns=""><i>stream</i></code> bound to the temporary file
561 stream. Returns the pathname of the file that has been
562 created. See <code xmlns=""><a href="#open-temporary">open-temporary</a></code> for
563 permitted options.
564 </clix:description></blockquote></p>
565 <p xmlns="">[Macro]<br><a class="none" name="with-open-temporary-file"><b>with-open-temporary-file</b> <i><clix:lambda-list xmlns:clix="http://bknr.net/clixdoc">(stream <tt>&amp;rest</tt> args <tt>&amp;key</tt> keep <tt>&amp;allow-other-keys</tt>) <tt>&amp;body</tt> body</clix:lambda-list></i>
566 =&gt;
567 <i>values</i></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
568 Create a temporary file using
569 <code xmlns=""><a href="#open-temporary">open-temporary</a></code> with
570 <code xmlns=""><i>args</i></code> and run <code xmlns=""><i>body</i></code>
571 with <code xmlns=""><i>stream</i></code> bound to the temporary file
572 stream. Returns the values returned by
573 <code xmlns=""><i>body</i></code>. By default, the file is deleted
574 when <code xmlns=""><i>body</i></code> is exited. If a true value is
575 passed in <code xmlns=""><i>keep</i></code>, the file is not deleted
576 when the body is exited. See
577 <code xmlns=""><a href="#open-temporary">open-temporary</a></code> for more permitted
578 options.
579 </clix:description></blockquote></p>
580 <p xmlns="">
581 [Special variable]<br><a class="none" name="*default-template*"><b>*default-template*</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
582 This variable can be set to a string representing the desired
583 default template for temporary file name generation. See
584 <code xmlns=""><a href="#open-temporary">open-temporary</a></code> for a description of the
585 template string format.
586 </clix:description></blockquote></p>
587 <p xmlns="">
588 [Condition type]<br><a class="none" name="cannot-create-temporary-file"><b>cannot-create-temporary-file</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
589 Signalled when an attempt to create unique temporary file name
590 failed after the established number of retries.
591 </clix:description></blockquote></p>
592 <p xmlns="">
593 [Condition type]<br><a class="none" name="invalid-temporary-pathname-template"><b>invalid-temporary-pathname-template</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
594 Signalled when the <code xmlns=""><i>template</i></code> argument to
595 <code xmlns=""><a href="#open-temporary">open-temporary</a></code> does not contain a valid
596 template string. The template string must contain a percent
597 sign, which is replaced by the generated random string to
598 yield the filename.
599 </clix:description></blockquote></p>
600 <p xmlns="">
601 [Condition type]<br><a class="none" name="missing-temp-environment-variable"><b>missing-temp-environment-variable</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
602 (Windows only) Signalled when the TEMP environment variable is
603 not set.
604 </clix:description></blockquote></p>
605 <p xmlns="">
606 [Logical Pathname Host]<br><a class="none" name="lp-host-temporary-files"><b>temporary-files</b></a><blockquote><clix:description xmlns:clix="http://bknr.net/clixdoc">
607 This logical pathname host defines where temporary files are
608 stored by default. It is initialized in a suitable system
609 specific fashion: On Unix and Unix-like systems, the directory
610 specified in the TMPDIR environment variable is used. If that
611 variable is not set, /tmp is used as the default. On Windows,
612 the directory specified in the TEMP environment variable is
613 used. If it is not set, a
614 <code xmlns=""><a href="#missing-temp-environment-variable">missing-temp-environment-variable</a></code> error
615 is signalled.
616 </clix:description></blockquote></p>
617
618
619 <h4><a class=none name="modifying">Modifying the file system</a></h4>
620
621 <p><br>[Function]
622 <br><a class=none name="copy-file"><b>copy-file</b> <i> from to <tt>&amp;key</tt> overwrite</i> =&gt; |</a>
623
624 <blockquote><br>
625 Copies the file designated by the non-wild <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname_designator">pathname designator</a> <code><i>from</i></code> to the
626 file designated by the non-wild <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname_designator">pathname designator</a> <code><i>to</i></code>. If <code><i>overwrite</i></code> is <em>true</em> (the default is <code>NIL</code>)
627 overwrites the file designated by <code><i>to</i></code> if it exists.
628 </blockquote>
629
630 <p><br>[Function]
631 <br><a class=none name="copy-stream"><b>copy-stream</b> <i> from to <tt>&amp;optional</tt> checkp</i> =&gt; |</a>
632
633 <blockquote><br> Copies into <code><i>to</i></code> (a stream)
634 from <code><i>from</i></code> (also a stream) until the end
635 of <code><i>from</i></code> is reached. The streams should have the
636 same <a
637 href="http://www.lispworks.com/documentation/HyperSpec/Body/f_stm_el.htm">element
638 type</a> unless they are bivalent. If <code><i>checkp</i></code> is
639 true (which is the default), the function will signal an error if the
640 element types aren't the same.
641 </blockquote>
642 <p><br>[Function]
643 <br><a class=none name="delete-directory-and-files"><b>delete-directory-and-files</b> <i> dirname <tt>&amp;key</tt> if-does-not-exist</i> =&gt; |</a>
644
645 <blockquote><br>
646 <p>
647 Recursively deletes all files and directories within the directory
648 designated by the non-wild <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_p.htm#pathname_designator">pathname designator</a> <code><i>dirname</i></code> including
649 <code><i>dirname</i></code> itself. <code><i>if-does-not-exist</i></code> must be one of <code>:ERROR</code> or <code>:IGNORE</code>
650 where <code>:ERROR</code> (the default) means that an error will be signaled if the directory
651 <code><i>dirname</i></code> does not exist.
652 </p>
653 <p>
654 <b>Warning:</b> this function <em>might</em> remove files from outside the
655 directory, if the directory that you are deleting contains links to
656 external files. This is currently fixed for SBCL and CCL.
657 </p>
658 </blockquote>
659
660 <h4>The <code>PATH</code> package</h4>
661
662 <p><br>[Package]
663 <br><a class=none name="package-path">(defpackage <b>path</b>)</a>
664
665 <blockquote>
666 Provides a set of short names for commonly used pathname manipulation
667 functions (these are all functions from the <code>cl-fad</code>
668 package which are being exported under different names):
669 <dl>
670 <dt><code>dirname</code></dt> <dd><a href="#pathname-as-directory">pathname-as-directory</a></dd>
671 <dt><code>basename</code></dt> <dd><code>cl:file-namestring</code></dd>
672 <dt><code>-e</code></dt> <dd><a href="#file-exists-p">file-exists-p</a></dd>
673 <dt><code>-d</code></dt> <dd><a href="#directory-exists-p">directory-exists-p</a></dd>
674 <dt><code>catfile</code></dt> <dd><a href="#merge-pathnames-as-file">merge-pathnames-as-file</a></dd>
675 <dt><code>catdir</code></dt> <dd><a href="#merge-pathnames-as-directory">merge-pathnames-as-directory</a></dd>
676 <dt><code>rm-r</code></dt> <dd><a href="#delete-directory-and-files">delete-directory-and-files</a></dd>
677 <dt><code>=</code></dt> <dd><a href="#pathname-equal">pathname-equal</a></dd>
678 <dt><code>absolute-p</code></dt> <dd><a href="#pathname-absolute-p">pathname-absolute-p</a></dd>
679 <dt><code>relative-p</code></dt> <dd><a href="#pathname-relative-p">pathname-relative-p</a></dd>
680 <dt><code>root-p</code></dt> <dd><a href="#pathname-root-p">pathname-root-p</a></dd>
681 </dl>
682 </blockquote>
683
684
685 <br>&nbsp;<br><h3><a class=none name="ack">Acknowledgements</a></h3>
686
687 The original code for this library was written by Peter Seibel for his
688 book <a href="http://www.gigamonkeys.com/book/"><em>Practical Common
689 Lisp</em></a>. I added some stuff and made sure it worked properly on
690 Windows, specifically with CCL. Thanks to James Bielman, Maciek
691 Pasternacki, Jack D. Unrue, Gary King, and Douglas Crosher who sent
692 patches for OpenMCL, ECL, ABCL, MCL, and Scieneer&nbsp;CL.
693
694 <p>
695 $Header: /usr/local/cvsrep/cl-fad/doc/index.html,v 1.33 2009/09/30 14:23:12 edi Exp $
696 <p><a href="http://weitz.de/index.html">BACK TO MY HOMEPAGE</a>
697
698 </body>
699 </html>
700