From 7d592af7d3a29f492b2d62bc5ac8b5c67b2bc83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 30 Nov 2025 20:27:38 +0100 Subject: Move logic of extracting artifacts to Job module --- src/Command/Extract.hs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'src/Command') 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) -- cgit v1.2.3