HELP: current-directory
{ $description "A variable holding the current directory as an absolute path. Words that use the filesystem do so in relation to this variable."
$nl
-"This variable should never be set directly; instead, use " { $link set-current-directory } " or " { $link with-directory } ". This preserves the invariant that the value of this variable is an absolute path." } ;
+ "This variable should never be set directly; instead, use " { $link set-current-directory } " or " { $link with-directory } ". This preserves the invariant that the value of this variable is an absolute path." } ;
+
+HELP: make-parent-directories
+{ $values { "path" "a pathname string" } }
+{ $description "Creates all parent directories of the path which do not yet exist." }
+{ $errors "Throws an error if the directories could not be created." } ;
HELP: set-current-directory
{ $values { "path" "a pathname string" } }
[ "touch bar" try-output-process ] with-directory
] unit-test
-] with-test-directory
-
+ { t } [
+ "one/two/three" make-parent-directories parent-directory exists?
+ ] unit-test
+] with-test-directory
! Creating directories
HOOK: make-directory io-backend ( path -- )
+DEFER: make-parent-directories
+
: make-directories ( path -- )
normalize-path trim-tail-separators dup {
[ "." = ]
[ empty? ]
[ exists? ]
} 1|| [
- dup parent-directory make-directories
+ make-parent-directories
dup make-directory
] unless drop ;
+: make-parent-directories ( filename -- filename )
+ dup parent-directory make-directories ;
+
! Listing directories
TUPLE: directory-entry name type ;
HOOK: copy-file io-backend ( from to -- )
M: object copy-file
- dup parent-directory make-directories
- binary <file-writer> [
+ make-parent-directories binary <file-writer> [
swap binary <file-reader> [
swap stream-copy
] with-disposal
[ \ file-delete-failed boa rethrow ] recover ;
M: windows copy-file ( from to -- )
- dup parent-directory make-directories
+ make-parent-directories
[ normalize-path ] bi@ 0 CopyFile win32-error=0/f ;
M: windows make-directory ( path -- )
[ append-path ] curry bi@
dup file-info directory?
[ drop make-directories ]
- [ swap [ parent-directory make-directories ] [ copy-file ] bi ] if ;
+ [ swap make-parent-directories copy-file ] if ;
PRIVATE>
! Copyright (C) 2014 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.data alien.strings arrays
-byte-arrays classes.struct combinators constructors
-continuations destructors forestdb.ffi forestdb.paths fry
-generalizations io.encodings.string io.encodings.utf8
-io.pathnames kernel libc math multiline namespaces sequences
-strings ;
+USING: accessors alien.c-types alien.data alien.strings byte-arrays
+classes.struct combinators constructors continuations destructors
+forestdb.ffi fry generalizations io.directories io.encodings.string
+io.encodings.utf8 io.pathnames kernel libc math multiline namespaces
+sequences strings ;
QUALIFIED: sets
IN: forestdb.lib
: fdb-open ( path config -- file-handle )
[ f void* <ref> ] 2dip
- [ absolute-path ensure-fdb-filename-directory ] dip
+ [ make-parent-directories ] dip
[ fdb_open fdb-check-error ] 3keep
2drop void* deref <fdb-file-handle> ;
: path-fdb-duplicates ( path -- seq )
directory-files [ canonical-fdb-name ] map members ;
-: ensure-fdb-directory ( filename -- filename )
- [ make-directories ] keep ;
-
-: ensure-fdb-filename-directory ( filename -- filename )
- [ parent-directory make-directories ] keep ;
-
! : path>next-vnode-version-name ( path -- path' )
! [ file-name ]