ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional ReplaceRegExp.java
Date Mon, 27 May 2002 15:57:40 GMT
bodewig     02/05/27 08:57:40

  Modified:    src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
                        Replace.java
               src/main/org/apache/tools/ant/taskdefs/optional Tag:
                        ANT_15_BRANCH ReplaceRegExp.java
  Log:
  Detect when we cannot overwrite the file we've been working on in
  <replace> and <replaceregexp> and throw an exception in this case.
  
  Reported by:	Eugene Voytitsky <viy@sunbay.com>
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.30.2.1  +8 -2      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Replace.java
  
  Index: Replace.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Replace.java,v
  retrieving revision 1.30
  retrieving revision 1.30.2.1
  diff -u -r1.30 -r1.30.2.1
  --- Replace.java	15 Apr 2002 15:33:09 -0000	1.30
  +++ Replace.java	27 May 2002 15:57:40 -0000	1.30.2.1
  @@ -413,8 +413,14 @@
               // otherwise, delete the new one
               if (changes) {
                   ++fileCount;
  -                src.delete();
  -                temp.renameTo(src);
  +                if (!src.delete()) {
  +                    throw new BuildException("Couldn't delete " + src,
  +                                             getLocation());
  +                }
  +                if (!temp.renameTo(src)) {
  +                    throw new BuildException("Couldn't rename temporary file " 
  +                                             + temp, getLocation());
  +                }
                   temp = null;
               }
           } catch (IOException ioe) {
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.9.2.3   +13 -5     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
  
  Index: ReplaceRegExp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java,v
  retrieving revision 1.9.2.2
  retrieving revision 1.9.2.3
  diff -u -r1.9.2.2 -r1.9.2.3
  --- ReplaceRegExp.java	24 May 2002 15:07:30 -0000	1.9.2.2
  +++ ReplaceRegExp.java	27 May 2002 15:57:40 -0000	1.9.2.3
  @@ -321,10 +321,15 @@
               w = null;
   
               if (changes) {
  -                f.delete();
  -                temp.renameTo(f);
  -            } else {
  -                temp.delete();
  +                if (!f.delete()) {
  +                    throw new BuildException("Couldn't delete " + f,
  +                                             getLocation());
  +                }
  +                if (!temp.renameTo(f)) {
  +                    throw new BuildException("Couldn't rename temporary file " 
  +                                             + temp, getLocation());
  +                }
  +                temp = null;
               }
           } finally {
               try {
  @@ -336,9 +341,12 @@
   
               try {
                   if (w != null) {
  -                    r.close();
  +                    w.close();
                   }
               } catch (Exception e) {
  +            }
  +            if (temp != null) {
  +                temp.delete();
               }
           }
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message