From 867ec77b0d9efa8819be2ebf82cace4600b929ee Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Sat, 10 Feb 2001 15:13:09 +0000 Subject: [PATCH] Add a warn on longfile mode ---------------------------------------------------------------------- git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268627 13f79535-47bb-0310-9956-ffa450edef68 --- docs/index.html | 8 ++++ .../org/apache/tools/ant/taskdefs/Tar.java | 37 +++++++++++++------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/docs/index.html b/docs/index.html index 0052975b6..33702ec10 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4954,6 +4954,14 @@ task to come up with a .tar.gz package.

("yes"/"no"). Default excludes are used when omitted. No + + longfile + One of truncate, fail, warn, + gnu. Determines how long files (>100 chars) are to be handled. + Early versions did not support such names, and modern versions do so in + incompatible ways. Default is warn. + No +

Examples

  <tar tarfile="${dist}/manual.tar" basedir="htdocs/manual"/>
diff --git a/src/main/org/apache/tools/ant/taskdefs/Tar.java b/src/main/org/apache/tools/ant/taskdefs/Tar.java
index b8db73abc..8727a237f 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Tar.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Tar.java
@@ -70,13 +70,16 @@ import org.apache.tools.ant.types.*;
 
 public class Tar extends MatchingTask {
 
+    // permissable values for longfile attribute
+    static public final String WARN = "warn";
+    static public final String FAIL = "fail";
     static public final String TRUNCATE = "truncate";
     static public final String GNU = "gnu";
 
     File tarFile;
     File baseDir;
     
-    String longFileMode = null;
+    String longFileMode = WARN;
     
     Vector filesets = new Vector();
     Vector fileSetFiles = new Vector();
@@ -107,10 +110,12 @@ public class Tar extends MatchingTask {
      *
      * Allowable values are
      *   truncate
+     *   fail
+     *   warn
      *   gnu
      */
-    public void setLongfile(String method) {
-        this.longFileMode = method;
+    public void setLongfile(String mode) {
+        this.longFileMode = mode;
     }
 
     public void execute() throws BuildException {
@@ -156,15 +161,7 @@ public class Tar extends MatchingTask {
         try {
             tOut = new TarOutputStream(new FileOutputStream(tarFile));
             tOut.setDebug(true);
-            if (longFileMode == null) {
-                tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR);
-            }
-            else if (longFileMode.equalsIgnoreCase(TRUNCATE)) {
-                tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE);
-            }
-            else if (longFileMode.equalsIgnoreCase(GNU)) {
-                tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
-            }
+            tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
         
             for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
                 TarFileSet fs = (TarFileSet)e.nextElement();
@@ -196,6 +193,22 @@ public class Tar extends MatchingTask {
         FileInputStream fIn = new FileInputStream(file);
 
         try {
+            if (vPath.length() >= TarConstants.NAMELEN) {
+                if (longFileMode.equalsIgnoreCase(TRUNCATE)) {
+                    log("Skipping: "+ vPath, Project.MSG_INFO);
+                    return;
+                } else if (longFileMode.equalsIgnoreCase(WARN)) {
+                    log("Entry: "+ vPath + " longer than " + 
+                        TarConstants.NAMELEN + " characters.", Project.MSG_WARN);
+                    log("Resulting tar file can only be processed successfully"
+                        + " by GNU compatible tar commands", Project.MSG_WARN);
+                } else if (longFileMode.equalsIgnoreCase(FAIL)) {
+                    throw new BuildException(
+                        "Entry: "+ vPath + " longer than " + 
+                        TarConstants.NAMELEN + "characters.", location);
+                }
+            }
+
             TarEntry te = new TarEntry(vPath);
             te.setSize(file.length());
             te.setModTime(file.lastModified());