diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebPackageWriter.java b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebPackageWriter.java index 29d85da74baf..327b8e73a87f 100644 --- a/java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebPackageWriter.java +++ b/java/code/src/com/redhat/rhn/taskomatic/task/repomd/DebPackageWriter.java @@ -36,6 +36,7 @@ import java.io.StringWriter; import java.util.Collection; import java.util.Optional; +import java.util.stream.Collectors; /** * @@ -62,6 +63,19 @@ public DebPackageWriter(Channel channel, String prefix) throws IOException { out = new BufferedWriter(new FileWriter(filenamePackages, true)); } + private String getFilename(PackageDto pkgDto) { + StringBuilder buf = new StringBuilder(); + buf.append("Filename: ").append(channelLabel).append("/getPackage/") + .append(pkgDto.getName()).append("_"); + String epoch = pkgDto.getEpoch(); + if (epoch != null && !epoch.equalsIgnoreCase("")) { + buf.append(epoch).append(":"); + } + buf.append(pkgDto.getVersion()).append("-").append(pkgDto.getRelease()) + .append(".").append(pkgDto.getArchLabel()).append(".deb"); + return buf.toString(); + } + /** * add package info to Packages file in repository * @@ -72,7 +86,21 @@ public void addPackage(PackageDto pkgDto) throws IOException { // we use the primary xml cache for debian package entry String pkgSnippet = pkgDto.getPrimaryXml(); if (ConfigDefaults.get().useDBRepodata() && !StringUtils.isBlank(pkgSnippet)) { - out.write(pkgSnippet); + // deb repos currently contain file path in the metadata specific to a channel which makes them + // unusable for cloned channels. With this we use most of the cached version to preserve speed while + // regenerating the file path. + String fixedSnippet = pkgSnippet.lines() + .map(line -> { + if (line.startsWith("Filename: ")) { + return getFilename(pkgDto); + } + else { + return line; + } + }) + .collect(Collectors.joining(System.lineSeparator())); + out.write(fixedSnippet); + out.newLine(); out.newLine(); return; } @@ -145,13 +173,7 @@ public void addPackage(PackageDto pkgDto) throws IOException { TaskConstants.TASK_QUERY_REPOMD_GENERATOR_CAPABILITY_BREAKS, pkgDto.getId(), "Breaks"); - buf.write("Filename: " + channelLabel + "/getPackage/"); - buf.write(pkgDto.getName() + "_"); - if (epoch != null && !epoch.equalsIgnoreCase("")) { - buf.write(epoch + ":"); - } - buf.write(pkgDto.getVersion() + "-" + pkgDto.getRelease()); - buf.write("." + pkgDto.getArchLabel() + ".deb"); + buf.write(getFilename(pkgDto)); buf.newLine(); // size of package, is checked by apt diff --git a/java/spacewalk-java.changes.kwalter.bsc1214982 b/java/spacewalk-java.changes.kwalter.bsc1214982 new file mode 100644 index 000000000000..3c871baa0534 --- /dev/null +++ b/java/spacewalk-java.changes.kwalter.bsc1214982 @@ -0,0 +1 @@ +- fix token issue with cloned deb channels (bsc#1214982)