Use proper repository file extension on import/export with metadata

This commit is contained in:
Eduard Heimbuch
2021-01-28 14:35:45 +01:00
parent c3ab6bc5d5
commit 845f0688f7
2 changed files with 13 additions and 2 deletions

View File

@@ -113,7 +113,7 @@ public class FullScmRepositoryExporter {
try (FileOutputStream repositoryFos = new FileOutputStream(repositoryFile)) {
service.getBundleCommand().bundle(repositoryFos);
}
TarArchiveEntry entry = new TarArchiveEntry(service.getRepository().getName() + ".dump");
TarArchiveEntry entry = new TarArchiveEntry(createRepositoryEntryName(service));
entry.setSize(repositoryFile.length());
taos.putArchiveEntry(entry);
Files.copy(repositoryFile.toPath(), taos);
@@ -123,6 +123,10 @@ public class FullScmRepositoryExporter {
}
}
private String createRepositoryEntryName(RepositoryService service) {
return String.format("%s.%s", service.getRepository().getName(), service.getBundleCommand().getFileExtension());
}
private void writeStoreData(Repository repository, TarArchiveOutputStream taos) throws IOException {
File newWorkdir = workdirProvider.createNewWorkdir(repository.getId());
try {

View File

@@ -109,7 +109,8 @@ public class FullScmRepositoryImporter {
private Repository importRepositoryFromFile(Repository repository, TarArchiveInputStream tais) throws IOException {
ArchiveEntry repositoryEntry = tais.getNextEntry();
if (repositoryEntry.getName().endsWith(".dump") && !repositoryEntry.isDirectory()) {
String repositoryEntryFileExtension = resolveFileExtensionForRepository(repository);
if (repositoryEntry.getName().endsWith(repositoryEntryFileExtension) && !repositoryEntry.isDirectory()) {
return repositoryManager.create(repository, repo -> {
try (RepositoryService service = serviceFactory.create(repo)) {
service.getUnbundleCommand().unbundle(new NoneClosingInputStream(tais));
@@ -129,6 +130,12 @@ public class FullScmRepositoryImporter {
}
}
private String resolveFileExtensionForRepository(Repository repository) {
try (RepositoryService repoService = serviceFactory.create(repository)) {
return "." + repoService.getBundleCommand().getFileExtension();
}
}
private void checkScmEnvironment(Repository repository, TarArchiveInputStream tais) throws IOException {
ArchiveEntry environmentEntry = tais.getNextEntry();
if (environmentEntry.getName().equals(SCM_ENVIRONMENT_FILE_NAME) && !environmentEntry.isDirectory() && environmentEntry.getSize() < _1_MB) {