     [ [ file-permissions ] dip swap set-file-permissions ] 2bi ;
 
 : with-unix-directory ( path quot -- )
-    [ opendir dup [ (io-error) ] unless ] dip
-    dupd curry swap '[ _ closedir io-error ] [ ] cleanup ; inline
+    dupd '[ _ _
+        [ opendir dup [ (io-error) ] unless ] dip
+        dupd curry swap '[ _ closedir io-error ] [ ] cleanup
+    ] with-directory ; inline
 
 HOOK: find-next-file os ( DIR* -- byte-array )
 

    [ readdir_r 0 = [ errno 0 = [ (io-error) ] unless ] unless ] 2keep
    void* deref [ drop f ] unless ;

: dirent-type>file-type ( ch -- type )
    H{
        { $ DT_BLK  +block-device+ }
        { $ DT_CHR  +character-device+ }

io.directories io.encodings.binary io.files.info.unix
io.encodings.utf8 io.files io.pathnames io.files.types kernel
math.bitwise sequences system unix unix.stat vocabs.loader
classes.struct unix.ffi literals libc vocabs io.files.info ;
IN: io.directories.unix

CONSTANT: file-mode 0o0666
