From 5034c2c241af7cb441c6c34c5e9914c34ccf7df4 Mon Sep 17 00:00:00 2001 From: Marc Strapetz Date: Thu, 10 Dec 2020 16:25:20 +0100 Subject: [PATCH] Refactoring Tar: extract getCanonicalPrefix() --- src/main/org/apache/tools/ant/taskdefs/Tar.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Tar.java b/src/main/org/apache/tools/ant/taskdefs/Tar.java index 76446fdc8..3b5b635eb 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tar.java @@ -405,12 +405,7 @@ public class Tar extends MatchingTask { return; } - String prefix = tarFileSet.getPrefix(this.getProject()); - // '/' is appended for compatibility with the zip task. - if (!prefix.isEmpty() && !prefix.endsWith("/")) { - prefix += "/"; - } - vPath = prefix + vPath; + vPath = getCanonicalPrefix(tarFileSet, this.getProject()) + vPath; } else { vPath = fullpath; } @@ -785,6 +780,15 @@ public class Tar extends MatchingTask { return tfs; } + private static String getCanonicalPrefix(TarFileSet tarFileSet, Project project) { + String prefix = tarFileSet.getPrefix(project); + // '/' is appended for compatibility with the zip task. + if (prefix.isEmpty() || prefix.endsWith("/")) { + return prefix; + } + return prefix += "/"; + } + /** * This is a FileSet with the option to specify permissions * and other attributes.