Skip to content

Commit

Permalink
Merge pull request #48 from yma96/1.1.x
Browse files Browse the repository at this point in the history
Enhance the optimization of archive generation efficiency
  • Loading branch information
yma96 authored May 21, 2024
2 parents 36aa7e1 + 25d64ea commit ef9eaf5
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -226,7 +227,7 @@ public String getStatus( String buildConfigId )
}

private void downloadArtifacts( final Map<String, String> downloadPaths, final HistoricalContentDTO content )
throws InterruptedException, ExecutionException
throws InterruptedException, ExecutionException, IOException
{
BasicCookieStore cookieStore = new BasicCookieStore();
ExecutorCompletionService<Boolean> executor = new ExecutorCompletionService<>( executorService );
Expand All @@ -236,6 +237,7 @@ private void downloadArtifacts( final Map<String, String> downloadPaths, final H
dir.delete();

fileTrackedContent( contentBuildDir, content );
unpackHistoricalArchive( contentBuildDir, content.getBuildConfigId() );

for ( String path : downloadPaths.keySet() )
{
Expand Down Expand Up @@ -300,6 +302,16 @@ private Optional<File> generateArchive( final List<String> 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 );
}

Expand Down Expand Up @@ -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<Boolean> 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( "<<<Already existed in historical archive, skip downloading, path: {}.", path );
return true;
}
final File dir = target.getParentFile();
dir.mkdirs();
final File part = new File( dir, target.getName() + PART_SUFFIX );
Expand Down

0 comments on commit ef9eaf5

Please sign in to comment.