ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/tar TarConstants.java TarEntry.java TarOutputStream.java
Date Thu, 01 Feb 2001 15:46:35 GMT
conor       01/02/01 07:46:34

  Modified:    .        build.xml
               src/main/org/apache/tools/ant/taskdefs Tar.java
               src/main/org/apache/tools/tar TarConstants.java
                        TarEntry.java TarOutputStream.java
  Log:
  Add support for long filenames in tar task. The tar task now takes an
  attribute "longfile" which can take either the value "truncate" or the
  value "gnu". If the attribute is omitted, an exception is thrown (the
  current behaviour). Truncation is currently silent but willbe fixed to
  give a warning.
  
  Restored building of tar files in the distribution target.
  
  Revision  Changes    Path
  1.126     +10 -10    jakarta-ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/build.xml,v
  retrieving revision 1.125
  retrieving revision 1.126
  diff -u -r1.125 -r1.126
  --- build.xml	2001/01/31 16:05:14	1.125
  +++ build.xml	2001/02/01 15:46:26	1.126
  @@ -384,14 +384,14 @@
            basedir="${dist.name}/.." 
            includes="${dist.name}/**"
            excludes="${dist.name}/lib/optional.jar"/>
  -    <!--
  -    <tar tarfile="${dist.base}/${dist.name}-bin.tar" 
  +    <tar longfile="gnu"
  +         tarfile="${dist.base}/${dist.name}-bin.tar" 
            basedir="${dist.name}/.." 
  -         includes="${dist.name}/**"/
  -         excludes="${dist.name}/lib/optional.jar">
  +         includes="${dist.name}/**"
  +         excludes="${dist.name}/lib/optional.jar"/>
       <gzip zipfile="${dist.base}/${dist.name}-bin.tar.gz" 
             src="${dist.base}/${dist.name}-bin.tar"/>
  -    -->
  +    <delete file="${dist.base}/${dist.name}-bin.tar"/>
       <copy file="${dist.name}/lib/optional.jar" tofile="${dist.base}/${dist.name}-optional.jar"/>
       <delete dir="${dist.name}" />
   
  @@ -402,13 +402,13 @@
       <zip zipfile="${dist.base}/${dist.name}-src.zip" 
            basedir="${dist.name}/.." 
            includes="${dist.name}/**"/>
  -    <!--
  -    <tar tarfile="${dist.base}/${dist.name}-src.tar" 
  -         basedir="${src.dist.dir}/.." 
  -         includes="${src.dist.dir}/**"/>
  +    <tar longfile="gnu"
  +         tarfile="${dist.base}/${dist.name}-src.tar" 
  +         basedir="${dist.name}/.." 
  +         includes="${dist.name}/**"/>
       <gzip zipfile="${dist.base}/${dist.name}-src.tar.gz" 
             src="${dist.base}/${dist.name}-src.tar"/>
  -    -->
  +    <delete file="${dist.base}/${dist.name}-src.tar"/>
       <delete dir="${dist.name}" />
     </target>
   
  
  
  
  1.9       +25 -0     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java
  
  Index: Tar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Tar.java	2001/01/03 14:18:31	1.8
  +++ Tar.java	2001/02/01 15:46:28	1.9
  @@ -68,9 +68,14 @@
   
   public class Tar extends MatchingTask {
   
  +    static public final String TRUNCATE = "truncate";
  +    static public final String GNU = "gnu";
  +
       File tarFile;
       File baseDir;
       
  +    String longFileMode = null;
  +    
       /**
        * This is the name/location of where to create the tar file.
        */
  @@ -84,6 +89,17 @@
       public void setBasedir(File baseDir) {
           this.baseDir = baseDir;
       }
  +    
  +    /**
  +     * Set how to handle long files.
  +     *
  +     * Allowable values are
  +     *   truncate
  +     *   gnu
  +     */
  +    public void setLongfile(String method) {
  +        this.longFileMode = method;
  +    }
   
       public void execute() throws BuildException {
           if (tarFile == null) {
  @@ -115,6 +131,15 @@
           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);
  +            }
   
               for (int i = 0; i < files.length; i++) {
                   File f = new File(baseDir,files[i]);
  
  
  
  1.3       +9 -0      jakarta-ant/src/main/org/apache/tools/tar/TarConstants.java
  
  Index: TarConstants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/tar/TarConstants.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TarConstants.java	2001/01/03 14:18:48	1.2
  +++ TarConstants.java	2001/02/01 15:46:31	1.3
  @@ -179,4 +179,13 @@
        */
       public static final String GNU_TMAGIC = "ustar  ";
   
  +    /**
  +     * The namr of the GNU tar entry which contains a long name.
  +     */
  +    public static final String GNU_LONGLINK = "././@LongLink";
  +    
  +    /**
  +     * Identifies the *next* file on the tape as having a long name.  
  +     */
  +    public static final byte LF_GNUTYPE_LONGNAME = (byte) 'L';
   }
  
  
  
  1.4       +8 -13     jakarta-ant/src/main/org/apache/tools/tar/TarEntry.java
  
  Index: TarEntry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/tar/TarEntry.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TarEntry.java	2001/01/21 00:43:22	1.3
  +++ TarEntry.java	2001/02/01 15:46:31	1.4
  @@ -178,11 +178,14 @@
           this.devMajor = 0;
           this.devMinor = 0;
   
  -        if (this.name.length() > NAMELEN) {
  -            throw new RuntimeException("file name '" + this.name 
  -                                             + "' is too long ( > " 
  -                                             + NAMELEN + " bytes)");
  -        } 
  +    }   
  +        
  +    /** 
  +     * Construct an entry with a name an a link flag.
  +     */ 
  +    public TarEntry(String name, byte linkFlag) {
  +        this(name);
  +        this.linkFlag = linkFlag;
       }   
           
       /** 
  @@ -242,14 +245,6 @@
           } else {
               this.mode = 0100644;
               this.linkFlag = LF_NORMAL;
  -        } 
  -        
  -        if (this.name.length() > NAMELEN) {
  -            throw new RuntimeException("file name '" + this.name 
  -                                             + "' is too long ( > " 
  -                                             + NAMELEN + " bytes)");
  -        
  -            // UNDONE When File lets us get the userName, use it!
           } 
           
           this.size = file.length();
  
  
  
  1.3       +32 -3     jakarta-ant/src/main/org/apache/tools/tar/TarOutputStream.java
  
  Index: TarOutputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/tar/TarOutputStream.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TarOutputStream.java	2001/01/03 14:18:48	1.2
  +++ TarOutputStream.java	2001/02/01 15:46:32	1.3
  @@ -69,6 +69,10 @@
    * @author Timothy Gerard Endres <a href="mailto:time@ice.com">time@ice.com</a>
    */
   public class TarOutputStream extends FilterOutputStream {
  +    static public final int LONGFILE_ERROR = 0;
  +    static public final int LONGFILE_TRUNCATE = 1;
  +    static public final int LONGFILE_GNU = 2;
  +    
       protected boolean   debug;
       protected int       currSize;
       protected int       currBytes;
  @@ -77,6 +81,7 @@
       protected int       assemLen;
       protected byte[]    assemBuf;
       protected TarBuffer buffer;
  +    protected int       longFileMode = LONGFILE_ERROR;
   
       public TarOutputStream(OutputStream os) {
           this(os, TarBuffer.DEFAULT_BLKSIZE, TarBuffer.DEFAULT_RCDSIZE);
  @@ -97,6 +102,11 @@
           this.oneBuf = new byte[1];
       }
   
  +    public void setLongFileMode(int longFileMode) {
  +        this.longFileMode = longFileMode;
  +    }
  +    
  +
       /**
        * Sets the debugging flag.
        * 
  @@ -154,6 +164,27 @@
        * @param entry The TarEntry to be written to the archive.
        */
       public void putNextEntry(TarEntry entry) throws IOException {
  +        if (entry.getName().length() > TarConstants.NAMELEN) {
  +
  +            if (longFileMode == LONGFILE_GNU) {
  +                // create a TarEntry for the LongLink, the contents
  +                // of which are the entry's name 
  +                TarEntry longLinkEntry = new TarEntry(TarConstants.GNU_LONGLINK,
  +                                                      TarConstants.LF_GNUTYPE_LONGNAME);
  +                 
  +                longLinkEntry.setSize(entry.getName().length() + 1);
  +                putNextEntry(longLinkEntry);                                          
         
  +                write(entry.getName().getBytes());
  +                write(0);
  +                closeEntry();
  +            }
  +            else if (longFileMode != LONGFILE_TRUNCATE) {
  +                throw new RuntimeException("file name '" + entry.getName() 
  +                                             + "' is too long ( > " 
  +                                             + TarConstants.NAMELEN + " bytes)");
  +            }
  +        } 
  +
           entry.writeEntryHeader(this.recordBuf);
           this.buffer.writeRecord(this.recordBuf);
   
  @@ -210,7 +241,7 @@
       /**
        * Writes bytes to the current tar archive entry.
        * 
  -     * This method simply calls read( byte[], int, int ).
  +     * This method simply calls write( byte[], int, int ).
        * 
        * @param wBuf The buffer to write to the archive.
        * @return The number of bytes read, or -1 at EOF.
  @@ -227,8 +258,6 @@
        * record buffering required by TarBuffer, and manages buffers
        * that are not a multiple of recordsize in length, including
        * assembling records from small buffers.
  -     * 
  -     * This method simply calls read( byte[], int, int ).
        * 
        * @param wBuf The buffer to write to the archive.
        * @param wOffset The offset in the buffer from which to get bytes.
  
  
  

Mime
View raw message