Browse Source

Fix for Tar-time

Submitted by:	Stefan Bodewig <bodewig@bost.de>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267679 13f79535-47bb-0310-9956-ffa450edef68
master
Arnout J. Kuiper 25 years ago
parent
commit
0fce1960af
2 changed files with 36 additions and 3 deletions
  1. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Tar.java
  2. +35
    -2
      src/main/org/apache/tools/ant/taskdefs/Untar.java

+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Tar.java View File

@@ -122,7 +122,7 @@ public class Tar extends MatchingTask {

TarEntry te = new TarEntry(vPath);
te.setSize(file.length());
te.setModTime(file.lastModified() / 1000);
te.setModTime(file.lastModified());
tOut.putNextEntry(te);

byte[] buffer = new byte[8 * 1024];


+ 35
- 2
src/main/org/apache/tools/ant/taskdefs/Untar.java View File

@@ -57,6 +57,9 @@ package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.*;
import org.apache.tools.tar.*;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
* Untar a file.
*
@@ -74,6 +77,23 @@ public class Untar extends Task {
* @exception BuildException Thrown in unrecoverable error.
*/
public void execute() throws BuildException {

Method setLastModified = null;
Long[] times = null;
// 1.0 is ruled out anyway, so this ensures 1.2 or above
if (project.getJavaVersion() != Project.JAVA_1_1) {
try {
setLastModified =
java.io.File.class.getMethod("setLastModified",
new Class[] {Long.TYPE});

times = new Long[1];
} catch (Exception e) {
project.log("File.setLastModified(long) not found",
Project.MSG_VERBOSE);
}
}
try {
if (source == null) {
throw new BuildException("No source specified");
@@ -115,8 +135,21 @@ public class Untar extends Task {

fos.close();
}
} catch( FileNotFoundException ex ) {
System.out.println("FileNotFoundException: " + te.getName() );

if (setLastModified != null) {
times[0] = new Long(te.getModTime().getTime());
try {
setLastModified.invoke(f, times);
} catch (Exception e) {
project.log("cannot invoke File.setLastModified(long)",
Project.MSG_VERBOSE);
setLastModified = null;
}
}

} catch(FileNotFoundException ex) {
project.log("FileNotFoundException: " + te.getName(),
Project.MSG_WARN);
}
}
} catch (IOException ioe) {


Loading…
Cancel
Save