Skip to content

Add recursive arg to mkdir #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/Node/FS/Async.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Node.FS.Async
, unlink
, rmdir
, mkdir
, mkdirRecursive
, mkdir'
, readdir
, utimes
Expand Down Expand Up @@ -75,7 +76,7 @@ fs ::
, realpath :: forall cache. Fn3 FilePath { | cache } (JSCallback FilePath) Unit
, unlink :: Fn2 FilePath (JSCallback Unit) Unit
, rmdir :: Fn2 FilePath (JSCallback Unit) Unit
, mkdir :: Fn3 FilePath String (JSCallback Unit) Unit
, mkdir :: Fn3 FilePath { recursive :: Boolean, mode :: String } (JSCallback Unit) Unit
, readdir :: Fn2 FilePath (JSCallback (Array FilePath)) Unit
, utimes :: Fn4 FilePath Int Int (JSCallback Unit) Unit
, readFile :: forall a opts. Fn3 FilePath { | opts } (JSCallback a) Unit
Expand Down Expand Up @@ -202,16 +203,33 @@ mkdir :: FilePath
-> Callback Unit
-> Effect Unit

mkdir = flip mkdir' $ mkPerms all all all
mkdir path = mkdir' path (mkPerms all all all)

-- | Makes a new directory and any directories that don't exist
-- | in the path. Similar to `mkdir -p`.
mkdirRecursive :: FilePath
-> Callback Unit
-> Effect Unit

mkdirRecursive path = mkdirRecursive' path (mkPerms all all all)

-- | Makes a new directory (and any directories that don't exist
-- | in the path) with the specified permissions.
mkdirRecursive'
:: FilePath
-> Perms
-> Callback Unit
-> Effect Unit
mkdirRecursive' file perms cb = mkEffect $ \_ -> runFn3
fs.mkdir file { recursive: true, mode: permsToString perms } (handleCallback cb)

-- | Makes a new directory with the specified permissions.
mkdir' :: FilePath
-> Perms
-> Callback Unit
-> Effect Unit

mkdir' file perms cb = mkEffect $ \_ -> runFn3
fs.mkdir file (permsToString perms) (handleCallback cb)
fs.mkdir file { recursive: false, mode: permsToString perms } (handleCallback cb)

-- | Reads the contents of a directory.
readdir :: FilePath
Expand Down
20 changes: 18 additions & 2 deletions src/Node/FS/Sync.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module Node.FS.Sync
, rmdir
, mkdir
, mkdir'
, mkdirRecursive
, mkdirRecursive'
, readdir
, utimes
, readFile
Expand Down Expand Up @@ -64,7 +66,7 @@ fs ::
, realpathSync :: forall cache. Fn2 FilePath { | cache } FilePath
, unlinkSync :: Fn1 FilePath Unit
, rmdirSync :: Fn1 FilePath Unit
, mkdirSync :: Fn2 FilePath String Unit
, mkdirSync :: Fn2 FilePath { recursive :: Boolean, mode :: String } Unit
, readdirSync :: Fn1 FilePath (Array FilePath)
, utimesSync :: Fn3 FilePath Int Int Unit
, readFileSync :: forall a opts. Fn2 FilePath { | opts } a
Expand Down Expand Up @@ -173,6 +175,20 @@ rmdir :: FilePath
rmdir file = mkEffect $ \_ -> runFn1
fs.rmdirSync file

-- | Makes a new directory.
mkdirRecursive
:: FilePath
-> Effect Unit
mkdirRecursive = flip mkdirRecursive' $ mkPerms all all all

-- | Makes a new directory with the specified permissions.
mkdirRecursive'
:: FilePath
-> Perms
-> Effect Unit
mkdirRecursive' file perms = mkEffect $ \_ -> runFn2
fs.mkdirSync file { recursive: true, mode: permsToString perms }

-- | Makes a new directory.
mkdir :: FilePath
-> Effect Unit
Expand All @@ -185,7 +201,7 @@ mkdir' :: FilePath
-> Effect Unit

mkdir' file perms = mkEffect $ \_ -> runFn2
fs.mkdirSync file (permsToString perms)
fs.mkdirSync file { recursive: false, mode: permsToString perms }

-- | Reads the contents of a directory.
readdir :: FilePath
Expand Down