From 2ed70fa5d64bfcafd14dcc2d66ac0b95d4a85b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 30 Nov 2025 13:27:58 +0100 Subject: =?UTF-8?q?Implement=20and=20test=20=E2=80=98extract=20--force?= =?UTF-8?q?=E2=80=99=20without=20copyRecursiveForce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Command/Extract.hs | 13 +++++--- test/script/artifact.et | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 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 diff --git a/test/script/artifact.et b/test/script/artifact.et index c2bfc30..d353b49 100644 --- a/test/script/artifact.et +++ b/test/script/artifact.et @@ -43,3 +43,86 @@ test ExtractArtifact: shell on n as s: cat ./extracted_subdir/fb expect /content b/ from s + + +test ExtractArtifactForce: + node n + local: + spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "run", "generate" ] + expect /job-finish generate done/ from p + + # TODO: test failure without --force + #local: + # shell on n: + # touch extracted + # spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "generate.first", "extracted" ] + #local: + + local: + shell on n: + touch extracted + spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "--force", "generate.first", "extracted" ] + local: + shell on n as s: + cat ./extracted + expect /content 1/ from s + + # TODO: test failure without --force + #local: + # shell on n: + # touch f1 + # spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "generate.first", "." ] + #local: + + local: + shell on n: + touch f1 + spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "--force", "generate.first", "." ] + local: + shell on n as s: + cat ./f1 + expect /content 1/ from s + + # TODO: test failure without --force + #local: + # shell on n: + # mkdir dir + # touch dir/existing_file + # spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "generate.dir", "." ] + #local: + + local: + shell on n: + mkdir dir + touch dir/existing_file + spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "--force", "generate.dir", "." ] + local: + shell on n as s: + ls dir + echo DONE + expect /f2/ from s + expect /fa/ from s + expect /subdir/ from s + expect /(.*)/ from s capture done + guard (done == "DONE") + + # TODO: test failure without --force + #local: + # shell on n: + # touch dir + # spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "generate.dir", "." ] + #local: + + local: + shell on n: + touch dir + spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "--force", "generate.dir", "." ] + local: + shell on n as s: + ls dir + echo DONE + expect /f2/ from s + expect /fa/ from s + expect /subdir/ from s + expect /(.*)/ from s capture done + guard (done == "DONE") -- cgit v1.2.3