From 6adb3fceef1ff45ec000ec36664321c3b9622cd7 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 8 Sep 2020 20:12:54 -0700 Subject: [PATCH 1/3] Add recursive arg to `mkdir` --- src/Node/FS/Async.purs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Node/FS/Async.purs b/src/Node/FS/Async.purs index 3ebc669..0e5ff6a 100644 --- a/src/Node/FS/Async.purs +++ b/src/Node/FS/Async.purs @@ -13,6 +13,7 @@ module Node.FS.Async , unlink , rmdir , mkdir + , mkdirRecursive , mkdir' , readdir , utimes @@ -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 @@ -202,16 +203,25 @@ mkdir :: FilePath -> Callback Unit -> Effect Unit -mkdir = flip mkdir' $ mkPerms all all all +mkdir path = mkdir' path false (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 = mkdir' path true (mkPerms all all all) -- | Makes a new directory with the specified permissions. mkdir' :: FilePath + -> Boolean -> Perms -> Callback Unit -> Effect Unit -mkdir' file perms cb = mkEffect $ \_ -> runFn3 - fs.mkdir file (permsToString perms) (handleCallback cb) +mkdir' file recurse perms cb = mkEffect $ \_ -> runFn3 + fs.mkdir file { recursive: recurse, mode: permsToString perms } (handleCallback cb) -- | Reads the contents of a directory. readdir :: FilePath From 0df9f002922af42a9be119571cfcf1bea0aafbaa Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 6 Jan 2022 14:32:28 -0800 Subject: [PATCH 2/3] Refactor to prevent breaking change --- src/Node/FS/Async.purs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Node/FS/Async.purs b/src/Node/FS/Async.purs index 0e5ff6a..77f9c10 100644 --- a/src/Node/FS/Async.purs +++ b/src/Node/FS/Async.purs @@ -203,7 +203,7 @@ mkdir :: FilePath -> Callback Unit -> Effect Unit -mkdir path = mkdir' path false (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`. @@ -211,17 +211,25 @@ mkdirRecursive :: FilePath -> Callback Unit -> Effect Unit -mkdirRecursive path = mkdir' path true (mkPerms all all all) +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 - -> Boolean -> Perms -> Callback Unit -> Effect Unit - -mkdir' file recurse perms cb = mkEffect $ \_ -> runFn3 - fs.mkdir file { recursive: recurse, mode: permsToString perms } (handleCallback cb) +mkdir' file perms cb = mkEffect $ \_ -> runFn3 + fs.mkdir file { recursive: false, mode: permsToString perms } (handleCallback cb) -- | Reads the contents of a directory. readdir :: FilePath From ba3e3011356810668eaca65f654b584e15478c4a Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 6 Jan 2022 14:36:02 -0800 Subject: [PATCH 3/3] Also add sync versions of mkdirRecursive --- src/Node/FS/Sync.purs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Node/FS/Sync.purs b/src/Node/FS/Sync.purs index 7e90288..0d6c94a 100644 --- a/src/Node/FS/Sync.purs +++ b/src/Node/FS/Sync.purs @@ -13,6 +13,8 @@ module Node.FS.Sync , rmdir , mkdir , mkdir' + , mkdirRecursive + , mkdirRecursive' , readdir , utimes , readFile @@ -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 @@ -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 @@ -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