diff options
| -rw-r--r-- | src/Command/Extract.hs | 3 | ||||
| -rw-r--r-- | src/Job.hs | 26 | ||||
| -rw-r--r-- | test/asset/artifact/minici.yaml | 14 | ||||
| -rw-r--r-- | test/script/artifact.et | 24 | 
4 files changed, 58 insertions, 9 deletions
| diff --git a/src/Command/Extract.hs b/src/Command/Extract.hs index cc92587..b21c63c 100644 --- a/src/Command/Extract.hs +++ b/src/Command/Extract.hs @@ -14,6 +14,7 @@ import System.FilePath  import Command  import Eval +import Job  import Job.Types @@ -103,4 +104,4 @@ cmdExtract (ExtractCommand ExtractOptions {..} ExtractArguments {..}) = do              liftIO (doesPathExist tpath) >>= \case                  True -> tfail $ "destination ‘" <> T.pack tpath <> "’ already exists"                  False -> return () -        liftIO $ copyFile (adir </> afile) tpath +        liftIO $ copyRecursiveForce (adir </> afile) tpath @@ -9,6 +9,9 @@ module Job (      JobManager(..), newJobManager, cancelAllJobs,      runJobs,      jobStorageSubdir, + +    copyRecursive, +    copyRecursiveForce,  ) where  import Control.Concurrent @@ -309,7 +312,7 @@ runJob job uses checkoutPath jdir = do      liftIO $ forM_ uses $ \aout -> do          let target = checkoutPath </> aoutWorkPath aout          createDirectoryIfMissing True $ takeDirectory target -        copyFile (aoutStorePath aout) target +        copyRecursive (aoutStorePath aout) target      bracket (liftIO $ openFile (jdir </> "log") WriteMode) (liftIO . hClose) $ \logs -> do          forM_ (jobRecipe job) $ \p -> do @@ -338,7 +341,7 @@ runJob job uses checkoutPath jdir = do              let target = adir </> T.unpack tname </> takeFileName path              liftIO $ do                  createDirectoryIfMissing True $ takeDirectory target -                copyFile path target +                copyRecursiveForce path target              return $ ArtifactOutput                  { aoutName = name                  , aoutWorkPath = makeRelative checkoutPath path @@ -349,3 +352,22 @@ runJob job uses checkoutPath jdir = do              { outName = jobName job              , outArtifacts = artifacts              } + + +copyRecursive :: FilePath -> FilePath -> IO () +copyRecursive from to = do +    doesDirectoryExist from >>= \case +        False -> do +            copyFile from to +        True -> do +            createDirectory to +            content <- listDirectory from +            forM_ content $ \name -> do +                copyRecursive  (from </> name) (to </> name) + +copyRecursiveForce :: FilePath -> FilePath -> IO () +copyRecursiveForce from to = do +    doesDirectoryExist to >>= \case +        False -> return () +        True  -> removeDirectoryRecursive to +    copyRecursive from to diff --git a/test/asset/artifact/minici.yaml b/test/asset/artifact/minici.yaml index 065ae84..7204bb3 100644 --- a/test/asset/artifact/minici.yaml +++ b/test/asset/artifact/minici.yaml @@ -3,15 +3,23 @@ job generate:    shell:      - echo "content 1" > f1 -    - mkdir subdir -    - echo "content 2" > subdir/f2 +    - mkdir -p dir/subdir +    - echo "content 2" > dir/f2 +    - echo "content a" > dir/fa +    - echo "content b" > dir/subdir/fb      - echo "content 3" > f3    artifact first:      path: f1    artifact second: -    path: subdir/f2 +    path: dir/f2    artifact third:      path: f3 + +  artifact dir: +    path: dir + +  artifact sdir: +    path: dir/subdir diff --git a/test/script/artifact.et b/test/script/artifact.et index f1fc74e..c2bfc30 100644 --- a/test/script/artifact.et +++ b/test/script/artifact.et @@ -7,21 +7,39 @@ asset scripts:  test ExtractArtifact:      node n      local: -        spawn on n as p args [ "${scripts.path}/minici.yaml", "run", "generate" ] +        spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "run", "generate" ]          expect /job-finish generate done/ from p      local: -        spawn on n as p args [ "${scripts.path}/minici.yaml", "extract", "generate.first", "extracted" ] +        spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "generate.first", "extracted" ]      local:          shell on n as s:              cat ./extracted          expect /content 1/ from s      local: -        spawn on n as p args [ "${scripts.path}/minici.yaml", "extract", "generate.second", "generate.third", "." ] +        spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "generate.second", "generate.third", "." ]      local:          shell on n as s:              cat ./f2              cat ./f3          expect /content 2/ from s          expect /content 3/ from s + +    local: +        spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "generate.dir", "." ] +    local: +        shell on n as s: +            cat ./dir/f2 +            cat ./dir/fa +            cat ./dir/subdir/fb +        expect /content 2/ from s +        expect /content a/ from s +        expect /content b/ from s + +    local: +        spawn on n as p args [ "--storage=.minici", "${scripts.path}/minici.yaml", "extract", "generate.sdir", "extracted_subdir" ] +    local: +        shell on n as s: +            cat ./extracted_subdir/fb +        expect /content b/ from s |