From 25d64ea4f63eb5351df3ccd9bca77e28bc9396a2 Mon Sep 17 00:00:00 2001 From: yma Date: Tue, 21 May 2024 10:28:00 +0800 Subject: [PATCH] Enhance the optimization of archive generation efficiency --- .../archive/controller/ArchiveController.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/commonjava/indy/service/archive/controller/ArchiveController.java b/src/main/java/org/commonjava/indy/service/archive/controller/ArchiveController.java index aa04dac..482d091 100644 --- a/src/main/java/org/commonjava/indy/service/archive/controller/ArchiveController.java +++ b/src/main/java/org/commonjava/indy/service/archive/controller/ArchiveController.java @@ -58,6 +58,7 @@ import java.util.concurrent.Executors; import java.util.stream.Collectors; import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; @ApplicationScoped @@ -226,7 +227,7 @@ public String getStatus( String buildConfigId ) } private void downloadArtifacts( final Map downloadPaths, final HistoricalContentDTO content ) - throws InterruptedException, ExecutionException + throws InterruptedException, ExecutionException, IOException { BasicCookieStore cookieStore = new BasicCookieStore(); ExecutorCompletionService executor = new ExecutorCompletionService<>( executorService ); @@ -236,6 +237,7 @@ private void downloadArtifacts( final Map downloadPaths, final H dir.delete(); fileTrackedContent( contentBuildDir, content ); + unpackHistoricalArchive( contentBuildDir, content.getBuildConfigId() ); for ( String path : downloadPaths.keySet() ) { @@ -300,6 +302,16 @@ private Optional generateArchive( final List paths, final Historic fis.close(); } zip.close(); + + for ( String path : paths ) + { + logger.debug( "Clean temporary content workplace dir {}, path {}", contentBuildDir, path ); + File artifact = new File( contentBuildDir, path ); + artifact.delete(); + } + logger.debug( "Clean temporary content workplace dir {}", contentBuildDir ); + dir.delete(); + return Optional.of( part ); } @@ -357,11 +369,42 @@ private void fileTrackedContent( String contentBuildDir, final HistoricalContent } } + private void unpackHistoricalArchive( String contentBuildDir, String buildConfigId ) + throws IOException + { + final File archive = new File( archiveDir, buildConfigId + ARCHIVE_SUFFIX ); + if ( !archive.exists() ) + { + logger.debug( "Don't find historical archive for buildConfigId: {}.", buildConfigId ); + return; + } + + logger.info( "Start unpacking historical archive for buildConfigId: {}.", buildConfigId ); + ZipInputStream inputStream = new ZipInputStream( new FileInputStream( archive ) ); + ZipEntry entry; + while ( ( entry = inputStream.getNextEntry() ) != null ) + { + File outputFile = new File( contentBuildDir, entry.getName() ); + outputFile.getParentFile().mkdirs(); + try ( FileOutputStream outputStream = new FileOutputStream( outputFile ) ) + { + inputStream.transferTo( outputStream ); + } + + } + inputStream.close(); + } + private Callable download( String contentBuildDir, final String path, final String filePath, final CookieStore cookieStore ) { return () -> { final File target = new File( contentBuildDir, filePath ); + if ( target.exists() ) + { + logger.trace( "<<