From d9f70ea81f56b8c04592362082201f45fd5dd093 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 10 Jun 2022 17:57:29 +0500 Subject: [PATCH 1/2] Add rmdir', rm, rm' --- src/Node/FS/Async.js | 1 + src/Node/FS/Async.purs | 31 ++++++++++++++++++++++++++++--- src/Node/FS/Sync.js | 1 + src/Node/FS/Sync.purs | 28 +++++++++++++++++++++++++--- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/Node/FS/Async.js b/src/Node/FS/Async.js index 1ed7423..64a4ef8 100644 --- a/src/Node/FS/Async.js +++ b/src/Node/FS/Async.js @@ -10,6 +10,7 @@ export { realpath as realpathImpl, unlink as unlinkImpl, rmdir as rmdirImpl, + rm as rmImpl, mkdir as mkdirImpl, readdir as readdirImpl, utimes as utimesImpl, diff --git a/src/Node/FS/Async.purs b/src/Node/FS/Async.purs index cd713c8..386d1eb 100644 --- a/src/Node/FS/Async.purs +++ b/src/Node/FS/Async.purs @@ -12,6 +12,9 @@ module Node.FS.Async , realpath' , unlink , rmdir + , rmdir' + , rm + , rm' , mkdir , mkdir' , readdir @@ -75,7 +78,8 @@ foreign import symlinkImpl :: Fn4 FilePath FilePath String (JSCallback Unit) Uni foreign import readlinkImpl :: Fn2 FilePath (JSCallback FilePath) Unit foreign import realpathImpl :: forall cache. Fn3 FilePath { | cache } (JSCallback FilePath) Unit foreign import unlinkImpl :: Fn2 FilePath (JSCallback Unit) Unit -foreign import rmdirImpl :: Fn2 FilePath (JSCallback Unit) Unit +foreign import rmdirImpl :: Fn3 FilePath { maxRetries :: Int, retryDelay :: Int } (JSCallback Unit) Unit +foreign import rmImpl :: Fn3 FilePath { force :: Boolean, maxRetries :: Int, recursive :: Boolean, retryDelay :: Int } (JSCallback Unit) Unit foreign import mkdirImpl :: Fn3 FilePath { recursive :: Boolean, mode :: String } (JSCallback Unit) Unit foreign import readdirImpl :: Fn2 FilePath (JSCallback (Array FilePath)) Unit foreign import utimesImpl :: Fn4 FilePath Int Int (JSCallback Unit) Unit @@ -189,9 +193,30 @@ unlink file cb = mkEffect $ \_ -> runFn2 rmdir :: FilePath -> Callback Unit -> Effect Unit +rmdir path cb = rmdir' path { maxRetries: 0, retryDelay: 100 } cb + +-- | Deletes a directory with options. +rmdir' :: FilePath + -> { maxRetries :: Int, retryDelay :: Int } + -> Callback Unit + -> Effect Unit +rmdir' path opts cb = mkEffect $ \_ -> runFn3 + rmdirImpl path opts (handleCallback cb) + +-- | Deletes a file or directory. +rm :: FilePath + -> Callback Unit + -> Effect Unit +rm path = rm' path { force: false, maxRetries: 100, recursive: false, retryDelay: 1000 } + +-- | Deletes a file or directory with options. +rm' :: FilePath + -> { force :: Boolean, maxRetries :: Int, recursive :: Boolean, retryDelay :: Int } + -> Callback Unit + -> Effect Unit +rm' path opts cb = mkEffect $ \_ -> runFn3 + rmImpl path opts (handleCallback cb) -rmdir file cb = mkEffect $ \_ -> runFn2 - rmdirImpl file (handleCallback cb) -- | Makes a new directory. mkdir :: FilePath diff --git a/src/Node/FS/Sync.js b/src/Node/FS/Sync.js index bd93b52..23dbfb9 100644 --- a/src/Node/FS/Sync.js +++ b/src/Node/FS/Sync.js @@ -10,6 +10,7 @@ export { realpathSync as realpathSyncImpl, unlinkSync as unlinkSyncImpl, rmdirSync as rmdirSyncImpl, + rmSync as rmSyncImpl, mkdirSync as mkdirSyncImpl, readdirSync as readdirSyncImpl, utimesSync as utimesSyncImpl, diff --git a/src/Node/FS/Sync.purs b/src/Node/FS/Sync.purs index 66f186a..c76edaa 100644 --- a/src/Node/FS/Sync.purs +++ b/src/Node/FS/Sync.purs @@ -11,6 +11,9 @@ module Node.FS.Sync , realpath' , unlink , rmdir + , rmdir' + , rm + , rm' , mkdir , mkdir' , readdir @@ -62,7 +65,8 @@ foreign import symlinkSyncImpl :: Fn3 FilePath FilePath String Unit foreign import readlinkSyncImpl :: Fn1 FilePath FilePath foreign import realpathSyncImpl :: forall cache. Fn2 FilePath { | cache } FilePath foreign import unlinkSyncImpl :: Fn1 FilePath Unit -foreign import rmdirSyncImpl :: Fn1 FilePath Unit +foreign import rmdirSyncImpl :: Fn2 FilePath { maxRetries :: Int, retryDelay :: Int } Unit +foreign import rmSyncImpl :: Fn2 FilePath { force :: Boolean, maxRetries :: Int, recursive :: Boolean, retryDelay :: Int } Unit foreign import mkdirSyncImpl :: Fn2 FilePath { recursive :: Boolean, mode :: String } Unit foreign import readdirSyncImpl :: Fn1 FilePath (Array FilePath) foreign import utimesSyncImpl :: Fn3 FilePath Int Int Unit @@ -166,9 +170,27 @@ unlink file = mkEffect $ \_ -> runFn1 -- | Deletes a directory. rmdir :: FilePath -> Effect Unit +rmdir path = rmdir' path { maxRetries: 0, retryDelay: 100 } + +-- | Deletes a directory with options. +rmdir' :: FilePath + -> { maxRetries :: Int, retryDelay :: Int } + -> Effect Unit +rmdir' path opts = mkEffect $ \_ -> runFn2 + rmdirSyncImpl path opts + +-- | Deletes a file or directory. +rm :: FilePath + -> Effect Unit +rm path = rm' path { force: false, maxRetries: 100, recursive: false, retryDelay: 1000 } + +-- | Deletes a file or directory with options. +rm' :: FilePath + -> { force :: Boolean, maxRetries :: Int, recursive :: Boolean, retryDelay :: Int } + -> Effect Unit +rm' path opts = mkEffect $ \_ -> runFn2 + rmSyncImpl path opts -rmdir file = mkEffect $ \_ -> runFn1 - rmdirSyncImpl file -- | Makes a new directory. mkdir :: FilePath From e757938a27be8ad268c19743189c41338758cbe4 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 10 Jun 2022 19:34:13 +0500 Subject: [PATCH 2/2] add changes --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd8135..d3a2df4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ Breaking changes: New features: +- Update rmdir' to take options arg +- Added rm and rm' version with and without options arg + Bugfixes: Other improvements: