Skip to content

Commit

Permalink
Solve the issue ctron#36
Browse files Browse the repository at this point in the history
  • Loading branch information
ThorAsgardDev committed Jan 30, 2023
1 parent d4d27b6 commit badecd0
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/main/java/de/dentrassi/rpm/builder/YumMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.stream.Collectors;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.compress.archivers.cpio.CpioArchiveEntry;
import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
Expand Down Expand Up @@ -235,6 +237,47 @@ private void addSinglePackage(final Path path, final Context context) throws IOE
rpmInformation = RpmInformations.makeInformation(ris);
}

// Retrieve all the files contained in the rpm (including symlink)
List<String> providedFiles = Lists.newArrayList();
try (RpmInputStream ris = new RpmInputStream(Files.newInputStream(path))) {
ris.getPayloadHeader();
ris.getSignatureHeader();

final CpioArchiveInputStream cpio = ris.getCpioStream();
CpioArchiveEntry cpioEntry;
while ((cpioEntry = cpio.getNextCPIOEntry()) != null) {
providedFiles.add(RpmInformations.normalize(cpioEntry.getName()));
}
cpio.close();
}

// Remove provided files from the required list
List<org.eclipse.packager.rpm.info.RpmInformation.Dependency> requiresToKeep = Lists.newArrayList();
for (org.eclipse.packager.rpm.info.RpmInformation.Dependency requiredDep : rpmInformation.getRequires()) {
boolean fileProvided = false;

for (String providedFile : providedFiles) {
if (requiredDep.getName().equals(providedFile)) {
fileProvided = true;
break;
}
}

if (!fileProvided) {
for (org.eclipse.packager.rpm.info.RpmInformation.Dependency providedDep : rpmInformation.getProvides()) {
if (requiredDep.getName().equals(providedDep.getName())) {
fileProvided = true;
break;
}
}
}

if (!fileProvided) {
requiresToKeep.add(requiredDep);
}
}
rpmInformation.setRequires(requiresToKeep);

context.addPackage(fileInformation, rpmInformation, singletonMap(SHA256, checksum), SHA256);

Files.copy(path, this.packagesPath.toPath().resolve(fileName), StandardCopyOption.COPY_ATTRIBUTES);
Expand Down

0 comments on commit badecd0

Please sign in to comment.