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.