commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject cvs commit: jakarta-commons/io/src/java/org/apache/commons/io FileUtils.java
Date Sat, 03 Jul 2004 11:20:46 GMT
jeremias    2004/07/03 04:20:45

  Modified:    io/src/test/org/apache/commons/io FileUtilsTestCase.java
               io/src/java/org/apache/commons/io FileUtils.java
  Log:
  Bug #29821
  Bugfix for FileUtils.touch(). An existings file was overwritten. With new testcase.
  Submitted by:	Christoffer Hammarström <kreiger.at.linuxgods.com>
  
  Revision  Changes    Path
  1.19      +18 -5     jakarta-commons/io/src/test/org/apache/commons/io/FileUtilsTestCase.java
  
  Index: FileUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/io/src/test/org/apache/commons/io/FileUtilsTestCase.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- FileUtilsTestCase.java	23 Apr 2004 22:47:39 -0000	1.18
  +++ FileUtilsTestCase.java	3 Jul 2004 11:20:45 -0000	1.19
  @@ -15,10 +15,7 @@
    */
   package org.apache.commons.io;
   
  -import java.io.File;
  -import java.io.FileInputStream;
  -import java.io.IOException;
  -import java.io.OutputStream;
  +import java.io.*;
   import java.net.URL;
   
   import org.apache.commons.io.testtools.FileBasedTestCase;
  @@ -448,6 +445,22 @@
           String contents = FileUtils.readFileToString(new File(filename), "UTF-8");
           assertTrue("FileUtils.fileRead()", contents.equals("This is a test"));
   
  +    }
  +
  +    public void testTouch() throws IOException {
  +        File file = new File(getTestDirectory(), "touch.txt") ;
  +        FileUtils.touch(file);
  +        assertTrue("FileUtils.touch() created file.", file.exists());
  +        FileOutputStream out = new FileOutputStream(file) ;
  +        assertEquals("Created empty file.", 0, file.length());
  +        out.write(0) ;
  +        out.close();
  +        assertEquals("Wrote one byte to file.", 1, file.length());
  +        file.setLastModified(0) ;
  +        assertEquals("Set lastModified to 0.", 0, file.lastModified());
  +        FileUtils.touch(file) ;
  +        assertEquals("FileUtils.touch() didn't empty the file.", 1, file.length());
  +        assertFalse("FileUtils.touch() changed lastModified.", 0 == file.lastModified())
;        
       }
   
   }
  
  
  
  1.33      +3 -2      jakarta-commons/io/src/java/org/apache/commons/io/FileUtils.java
  
  Index: FileUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/io/src/java/org/apache/commons/io/FileUtils.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- FileUtils.java	13 Jun 2004 04:58:07 -0000	1.32
  +++ FileUtils.java	3 Jul 2004 11:20:45 -0000	1.33
  @@ -121,8 +121,9 @@
        * @throws IOException If an I/O problem occurs
        */
       public static void touch(File file) throws IOException {
  -        OutputStream out = new java.io.FileOutputStream(file);
  +        OutputStream out = new java.io.FileOutputStream(file, true);
           IOUtils.closeQuietly(out);
  +        file.setLastModified(System.currentTimeMillis());
       }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message