From ed46fc49464f364c11492448ae15b12f26628e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=B6ser=2C=20Daniel?= Date: Wed, 28 Feb 2024 09:39:39 +0100 Subject: [PATCH] Handle intermediate directories of collect entries in MissingDirectoryTracker --- .../pom.xml | 136 ++++++++++++++++++ .../src/main/data/x/y/foobar | 0 .../verify.groovy | 25 ++++ .../rpm/builder/MissingDirectoryTracker.java | 46 ++++-- 4 files changed, 197 insertions(+), 10 deletions(-) create mode 100644 src/it/test19-intermediate-directories-collect/pom.xml create mode 100644 src/it/test19-intermediate-directories-collect/src/main/data/x/y/foobar create mode 100644 src/it/test19-intermediate-directories-collect/verify.groovy diff --git a/src/it/test19-intermediate-directories-collect/pom.xml b/src/it/test19-intermediate-directories-collect/pom.xml new file mode 100644 index 0000000..ffebda0 --- /dev/null +++ b/src/it/test19-intermediate-directories-collect/pom.xml @@ -0,0 +1,136 @@ + + + 4.0.0 + + de.dentrassi.maven.rpm.test + test19 + 1.0.0-SNAPSHOT + jar + + Test Package #19 + + Test explicitly adding and applying rules for implicitly created intermediate directories with collect entries. + + + http://dentrassi.de + + + Jens Reimann + http://dentrassi.de + + + + + Eclipse Public License - v 1.0 + repo + https://www.eclipse.org/legal/epl-v10.html + + + + + UTF-8 + UTF-8 + true + + 2009-01-01T12:00:00+01:00 + + + + + + + de.dentrassi.maven + rpm + @project.version@ + + + + rpm + + + false + Application/Misc + + + ${keyId} + ${user.home}/.gnupg/secring.gpg + ${passphrase} + SHA1 + ${skipSigning} + + + + /opt/mycompany/myapp + + + + + my-default + + + + /opt/mycompany + + mygeneraluser + mygeneralgroup + 0111 + + + + /opt/mycompany/myapp + + myuser + mygroup + 0555 + + + + /opt/mycompany/myapp + directory + + 0777 + + + + + + + + /opt/mycompany/myapp/a/b + + ${project.basedir}/src/main/data + false + + my-default + + + /opt/mycompany/myapp/c/d + + ${project.basedir}/src/main/data + true + + my-default + + + + + + + + + + + + + sign + + false + + + false + + + + + \ No newline at end of file diff --git a/src/it/test19-intermediate-directories-collect/src/main/data/x/y/foobar b/src/it/test19-intermediate-directories-collect/src/main/data/x/y/foobar new file mode 100644 index 0000000..e69de29 diff --git a/src/it/test19-intermediate-directories-collect/verify.groovy b/src/it/test19-intermediate-directories-collect/verify.groovy new file mode 100644 index 0000000..7fd6bb6 --- /dev/null +++ b/src/it/test19-intermediate-directories-collect/verify.groovy @@ -0,0 +1,25 @@ +def dump() { + Process proc = ('rpm -q --dump -p ' + basedir + "/target/*.rpm").execute() + return proc.in.getText().trim() +} + +def actual = dump() +println "Dump:\n" + actual + +def expected = """\ + /opt/mycompany/myapp 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040777 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/a 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040777 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/a/b 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040777 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/a/b/x/y/foobar 0 1230807600 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0100555 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/c 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040777 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/c/d 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040777 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/c/d/x 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040777 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/c/d/x/y 0 1230807600 0000000000000000000000000000000000000000000000000000000000000000 040777 myuser mygroup 0 0 0 X + /opt/mycompany/myapp/c/d/x/y/foobar 0 1230807600 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0100555 myuser mygroup 0 0 0 X""".stripIndent() + +if (actual != expected) { + System.out.format("RPM dump doesn't match - actual:%n%s%nexpected:%n%s%n", actual, expected); + return false; +} + +return true; diff --git a/src/main/java/de/dentrassi/rpm/builder/MissingDirectoryTracker.java b/src/main/java/de/dentrassi/rpm/builder/MissingDirectoryTracker.java index 480f994..c3d5789 100644 --- a/src/main/java/de/dentrassi/rpm/builder/MissingDirectoryTracker.java +++ b/src/main/java/de/dentrassi/rpm/builder/MissingDirectoryTracker.java @@ -59,20 +59,39 @@ private void addMissingDirectoriesFromPath(String targetName, FileInformationPro if (provider instanceof MojoFileInformationProvider) { MojoFileInformationProvider mojoProvider = (MojoFileInformationProvider) provider; - for (String intermediateDirectory : getIntermediateDirectories(targetName)) { - if (startsPathWithPrefix(intermediateDirectory) && !explicitAddedDirectories.contains(intermediateDirectory)) { - missingDirectories.computeIfAbsent(intermediateDirectory, - (String directory) -> new MojoFileInformationProvider( - mojoProvider.getRulesetEval(), - mojoProvider.getRuleId(), - null, - mojoProvider.getLogger(), - mojoProvider.getTimestamp())); - } + List intermediateDirectories; + if (containsCollectEntry(mojoProvider)) { + // collect handles intermediate directories by themselves via flag 'directories' + // -> only use base directory (entry name of collect) as target path to calculate + // intermediate directories + targetName = mojoProvider.getEntry().getName(); + intermediateDirectories = getIntermediateDirectoriesIncludingTarget(targetName); + } else { + intermediateDirectories = getIntermediateDirectories(targetName); } + + for (String intermediateDirectory : intermediateDirectories) { + addIfIsMissingDirectory(intermediateDirectory, mojoProvider); + } + } + } + + private void addIfIsMissingDirectory(String intermediateDirectory, MojoFileInformationProvider mojoProvider) { + if (startsPathWithPrefix(intermediateDirectory) && !explicitAddedDirectories.contains(intermediateDirectory)) { + missingDirectories.computeIfAbsent(intermediateDirectory, + (String directory) -> new MojoFileInformationProvider( + mojoProvider.getRulesetEval(), + mojoProvider.getRuleId(), + null, + mojoProvider.getLogger(), + mojoProvider.getTimestamp())); } } + private boolean containsCollectEntry(MojoFileInformationProvider mojoProvider) { + return mojoProvider.getEntry().getCollect() != null; + } + private boolean startsPathWithPrefix(String directory) { return baseDirectories.stream().anyMatch(directory::startsWith); } @@ -95,4 +114,11 @@ private List getIntermediateDirectories(String targetName) { return intermediateDirectories; } + private List getIntermediateDirectoriesIncludingTarget(String targetName) { + List intermediateDirectories = getIntermediateDirectories(targetName); + intermediateDirectories.add(targetName); + + return intermediateDirectories; + } + }