]> gitweb.factorcode.org Git - factor.git/blob - basis/io/files/temp/temp.factor
a9109bd857d0198d9721a5758e148be6972f6e98
[factor.git] / basis / io / files / temp / temp.factor
1 ! (c)2012 Joe Groff bsd license
2 USING: combinators init io.directories io.pathnames kernel
3 namespaces system vocabs ;
4 IN: io.files.temp
5
6 HOOK: default-temp-directory os ( -- path )
7
8 SYMBOL: current-temp-directory
9
10 : temp-directory ( -- path )
11     current-temp-directory get ;
12
13 : temp-file ( name -- path )
14     temp-directory prepend-path ;
15
16 : with-temp-directory ( quot -- )
17     [ temp-directory ] dip with-directory ; inline
18
19 HOOK: default-cache-directory os ( -- path )
20
21 SYMBOL: current-cache-directory
22
23 : cache-directory ( -- path )
24     current-cache-directory get ;
25
26 : cache-file ( name -- path )
27     cache-directory prepend-path ;
28
29 : with-cache-directory ( quot -- )
30     [ cache-directory ] dip with-directory ; inline
31
32 {
33     { [ os windows? ] [ "io.files.temp.windows" ] }
34     { [ os macosx? ] [ "io.files.temp.macosx" ] }
35     { [ os unix? ] [ "io.files.temp.unix" ] }
36 } cond require
37
38 [
39     default-temp-directory dup make-directories
40     current-temp-directory set-global
41
42     default-cache-directory dup make-directories
43     current-cache-directory set-global
44 ] "io.files.temp" add-startup-hook