summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2025-11-30 13:27:58 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2025-11-30 13:27:58 +0100
commit2ed70fa5d64bfcafd14dcc2d66ac0b95d4a85b26 (patch)
treef7603d88e6a9ad3e2c145ebb5df596c228de2ef2 /src
parent60d653c05420f4ca7b41e73bb252268c34d946fe (diff)
Implement and test ‘extract --force’ without copyRecursiveForce
Diffstat (limited to 'src')
-rw-r--r--src/Command/Extract.hs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/Command/Extract.hs b/src/Command/Extract.hs
index a9ab292..bb4498d 100644
--- a/src/Command/Extract.hs
+++ b/src/Command/Extract.hs
@@ -98,8 +98,11 @@ cmdExtract (ExtractCommand ExtractOptions {..} ExtractArguments {..}) = do
wpath <- liftIO $ readFile (adir </> "path")
let tpath | isdir = extractDestination </> takeFileName wpath
| otherwise = extractDestination
- when (not extractForce) $ do
- liftIO (doesPathExist tpath) >>= \case
- True -> tfail $ "destination ‘" <> T.pack tpath <> "’ already exists"
- False -> return ()
- liftIO $ copyRecursiveForce (adir </> "data") tpath
+ liftIO (doesPathExist tpath) >>= \case
+ True
+ | extractForce -> liftIO (doesDirectoryExist tpath) >>= \case
+ True -> liftIO $ removeDirectoryRecursive tpath
+ False -> liftIO $ removeFile tpath
+ | otherwise -> tfail $ "destination ‘" <> T.pack tpath <> "’ already exists"
+ False -> return ()
+ liftIO $ copyRecursive (adir </> "data") tpath