diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2025-11-30 20:27:38 +0100 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-11-30 20:27:38 +0100 |
| commit | 7d592af7d3a29f492b2d62bc5ac8b5c67b2bc83c (patch) | |
| tree | 36aadd1b381fe63865d2ee7e1b23ad513b054a95 /src/Command | |
| parent | 2ed70fa5d64bfcafd14dcc2d66ac0b95d4a85b26 (diff) | |
Move logic of extracting artifacts to Job module
Diffstat (limited to 'src/Command')
| -rw-r--r-- | src/Command/Extract.hs | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/Command/Extract.hs b/src/Command/Extract.hs index bb4498d..366128c 100644 --- a/src/Command/Extract.hs +++ b/src/Command/Extract.hs @@ -79,25 +79,17 @@ cmdExtract (ExtractCommand ExtractOptions {..} ExtractArguments {..}) = do _:_:_ -> tfail $ "destination ‘" <> T.pack extractDestination <> "’ is not a directory" _ -> return False - forM_ extractArtifacts $ \( ref, ArtifactName aname ) -> do - [ jid@(JobId ids) ] <- either tfail (return . map jobId) =<< + forM_ extractArtifacts $ \( ref, aname ) -> do + [ jid ] <- either tfail (return . map jobId) =<< return . either (Left . textEvalError) (first T.pack . jobsetJobsEither) =<< liftIO (runEval (evalJobReference ref) einput) - let jdir = joinPath $ (storageDir :) $ ("jobs" :) $ map (T.unpack . textJobIdPart) ids - adir = jdir </> "artifacts" </> T.unpack aname + tpath <- if + | isdir -> do + wpath <- either tfail return =<< runExceptT (getArtifactWorkPath storageDir jid aname) + return $ extractDestination </> takeFileName wpath + | otherwise -> return extractDestination - liftIO (doesDirectoryExist jdir) >>= \case - True -> return () - False -> tfail $ "job ‘" <> textJobId jid <> "’ not yet executed" - - liftIO (doesDirectoryExist adir) >>= \case - True -> return () - False -> tfail $ "artifact ‘" <> aname <> "’ of job ‘" <> textJobId jid <> "’ not found" - - wpath <- liftIO $ readFile (adir </> "path") - let tpath | isdir = extractDestination </> takeFileName wpath - | otherwise = extractDestination liftIO (doesPathExist tpath) >>= \case True | extractForce -> liftIO (doesDirectoryExist tpath) >>= \case @@ -105,4 +97,5 @@ cmdExtract (ExtractCommand ExtractOptions {..} ExtractArguments {..}) = do False -> liftIO $ removeFile tpath | otherwise -> tfail $ "destination ‘" <> T.pack tpath <> "’ already exists" False -> return () - liftIO $ copyRecursive (adir </> "data") tpath + + either tfail return =<< runExceptT (copyArtifact storageDir jid aname tpath) |