ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yuji Yamano <yyam...@kt.rim.or.jp>
Subject Re: fixing crlf without changing timestamp
Date Thu, 03 Mar 2005 15:35:58 GMT
"michael sorens" <msorens@softhome.net> writes:

> Is it possible to run <fixcrlf> without changing a file's
> modification time? Or perhaps a way to use <touch> to restore the
> original modification time after the <fixcrlf> (on a group of
> files)?  I actually want to run fixcrlf in conjunction with copy
> (which has the preservelastmodified attribute to retain the
> modification time) but I see no way to do this.

The fixcrlf task doesn't support it yet. Could you try this patch?

Index: FixCRLF.java
===================================================================
RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java,v
retrieving revision 1.64
diff -u -u -r1.64 FixCRLF.java
--- FixCRLF.java	25 Feb 2005 00:33:00 -0000	1.64
+++ FixCRLF.java	3 Mar 2005 15:30:19 -0000
@@ -118,6 +118,7 @@
     private int tabs;
     private boolean javafiles = false;
     private boolean fixlast = true;
+    private boolean preserveLastModified = false;
 
     private File srcDir;
     private File destDir = null;
@@ -319,6 +320,13 @@
     }
 
     /**
+     * Set to true if keeping the last modified time as the original files.
+     */
+    public void setPreserveLastModified(boolean preserve) {
+        preserveLastModified = preserve;
+    }
+
+    /**
      * Executes the task.
      */
     public void execute() throws BuildException {
@@ -381,6 +389,7 @@
 
     private void processFile(String file) throws BuildException {
         File srcFile = new File(srcDir, file);
+        long lastModified = srcFile.lastModified();
         File destD = destDir == null ? srcDir : destDir;
         File tmpFile = null;
         BufferedWriter outWriter;
@@ -557,6 +566,10 @@
 
             if (destIsWrong) {
                 FILE_UTILS.rename(tmpFile, destFile);
+                if (preserveLastModified) {
+                    log("preserved lastModified", Project.MSG_DEBUG);
+                    FILE_UTILS.setFileLastModified(destFile, lastModified);
+                }
                 tmpFile = null;
             }
 
-- 
Yuji Yamano <yyamano@kt.rim.or.jp>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message