io.files.temp: allow changing of current temp and cache directory.

locals-and-roots
John Benediktsson 2016-03-16 15:19:10 -07:00
parent 47ae304ff7
commit 33b6c0426d
5 changed files with 40 additions and 34 deletions

View File

@ -22,22 +22,18 @@ FUNCTION: id NSSearchPathForDirectoriesInDomains (
CONSTANT: factor-bundle-name "org.factorcode.Factor" CONSTANT: factor-bundle-name "org.factorcode.Factor"
: (make-factor-bundle-subdir) ( path -- path ) : factor-bundle-subdir ( path -- path )
factor-bundle-name append-path dup make-directories ; factor-bundle-name append-path ;
: (first-existing) ( paths -- path ) : first-existing ( paths -- path )
[ exists? ] map-find nip [ exists? ] map-find nip
[ "no user cache directory found" throw ] unless* ; inline [ "no user cache directory found" throw ] unless* ; inline
PRIVATE> PRIVATE>
: (temp-directory) ( -- path ) M: macosx default-temp-directory
NSTemporaryDirectory CF>string (make-factor-bundle-subdir) ; NSTemporaryDirectory CF>string factor-bundle-subdir ;
M: macosx temp-directory (temp-directory) ; M: macosx default-cache-directory
: (cache-directory) ( -- path )
NSCachesDirectory NSUserDomainMask 1 NSSearchPathForDirectoriesInDomains NSCachesDirectory NSUserDomainMask 1 NSSearchPathForDirectoriesInDomains
plist> (first-existing) (make-factor-bundle-subdir) ; plist> first-existing factor-bundle-subdir ;
M: macosx cache-directory (cache-directory) ;

View File

@ -4,12 +4,14 @@ IN: io.files.temp
ARTICLE: "io.files.temp" "Temporary files" ARTICLE: "io.files.temp" "Temporary files"
"Pathnames relative to the system's temporary file directory:" "Pathnames relative to the system's temporary file directory:"
{ $subsections { $subsections
current-temp-directory
temp-file temp-file
temp-directory temp-directory
with-temp-directory with-temp-directory
} }
"Pathnames relative to Factor's cache directory, used to store persistent intermediate files and resources:" "Pathnames relative to Factor's cache directory, used to store persistent intermediate files and resources:"
{ $subsections { $subsections
current-cache-directory
cache-file cache-file
cache-directory cache-directory
with-cache-directory with-cache-directory

View File

@ -1,10 +1,18 @@
! (c)2012 Joe Groff bsd license ! (c)2012 Joe Groff bsd license
USING: combinators io.directories io.pathnames kernel system USING: combinators io.directories io.pathnames kernel
vocabs ; namespaces system vocabs ;
IN: io.files.temp IN: io.files.temp
HOOK: temp-directory os ( -- path ) HOOK: default-temp-directory os ( -- path )
HOOK: cache-directory os ( -- path )
SYMBOL: current-temp-directory
current-temp-directory [
default-temp-directory dup make-directories
] initialize
: temp-directory ( -- path )
current-temp-directory get ;
: temp-file ( name -- path ) : temp-file ( name -- path )
temp-directory prepend-path ; temp-directory prepend-path ;
@ -12,6 +20,17 @@ HOOK: cache-directory os ( -- path )
: with-temp-directory ( quot -- ) : with-temp-directory ( quot -- )
[ temp-directory ] dip with-directory ; inline [ temp-directory ] dip with-directory ; inline
HOOK: default-cache-directory os ( -- path )
SYMBOL: current-cache-directory
current-cache-directory [
default-cache-directory dup make-directories
] initialize
: cache-directory ( -- path )
current-cache-directory get ;
: cache-file ( name -- path ) : cache-file ( name -- path )
cache-directory prepend-path ; cache-directory prepend-path ;

View File

@ -1,14 +1,7 @@
! (c)2012 Joe Groff bsd license ! (c)2012 Joe Groff bsd license
USING: io.directories io.files.temp io.pathnames kernel memoize USING: io.files.temp io.pathnames system ;
system ;
IN: io.files.temp.unix IN: io.files.temp.unix
MEMO: (temp-directory) ( -- path ) M: unix default-temp-directory "/tmp/factor-temp" ;
"/tmp/factor-temp" dup make-directories ;
M: unix temp-directory (temp-directory) ; M: unix default-cache-directory home ".factor-cache" append-path ;
MEMO: (cache-directory) ( -- path )
home ".factor-cache" append-path dup make-directories ;
M: unix cache-directory (cache-directory) ;

View File

@ -9,7 +9,7 @@ IN: io.files.temp.windows
<PRIVATE <PRIVATE
: (get-temp-directory) ( -- path ) : get-temp-directory ( -- path )
MAX_PATH 1 + dup WCHAR <c-array> [ GetTempPath ] keep MAX_PATH 1 + dup WCHAR <c-array> [ GetTempPath ] keep
swap win32-error=0/f swap win32-error=0/f
alien>native-string ; alien>native-string ;
@ -25,13 +25,9 @@ PRIVATE>
[ SHGetFolderPath ] keep [ SHGetFolderPath ] keep
swap check-ole32-error alien>native-string ; swap check-ole32-error alien>native-string ;
M: windows default-temp-directory
get-temp-directory "factorcode.org\\Factor" append-path ;
MEMO: (temp-directory) ( -- path ) M: windows default-cache-directory
(get-temp-directory) "factorcode.org\\Factor" append-path dup make-directories ; get-appdata-directory "factorcode.org\\Factor" append-path ;
M: windows temp-directory (temp-directory) ;
MEMO: (cache-directory) ( -- path )
get-appdata-directory "factorcode.org\\Factor" append-path dup make-directories ;
M: windows cache-directory (cache-directory) ;