All,

I've had this sitting around in a stash for ages; just finally applied it, now.

If there are no objections, I'll back-port this to the other branches. java.nio.file.Files.move() was added in Java 7 so it should be available in all currently-supported environments.

-chris

On 10/18/23 22:09, [email protected] wrote:
This is an automated email from the ASF dual-hosted git repository.

schultz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
      new 7d301f5f9a Use a better "move" method.
7d301f5f9a is described below

commit 7d301f5f9aa1ac7c8d82336594cef2fd0702d0e4
Author: Christopher Schultz <[email protected]>
AuthorDate: Wed Oct 18 22:08:42 2023 -0400

     Use a better "move" method.
---
  java/org/apache/catalina/ha/deploy/FarmWarDeployer.java | 9 +++++----
  webapps/docs/changelog.xml                              | 5 +++++
  2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java 
b/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
index 1fb548314a..16e821c282 100644
--- a/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
+++ b/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
@@ -19,6 +19,7 @@ package org.apache.catalina.ha.deploy;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.IOException;
+import java.nio.file.Files;
  import java.util.HashMap;
import javax.management.MBeanServer;
@@ -224,10 +225,10 @@ public class FarmWarDeployer extends ClusterListener 
implements ClusterDeployer,
                          if (tryAddServiced(contextName)) {
                              try {
                                  remove(contextName);
-                                if (!factory.getFile().renameTo(deployable)) {
-                                    log.error(
-                                            
sm.getString("farmWarDeployer.renameFail", factory.getFile(), deployable));
-                                }
+
+                                Files.move(factory.getFile().toPath(), 
deployable.toPath());
+                            } catch (IOException ioe) {
+                                
log.error(sm.getString("farmWarDeployer.renameFail", factory.getFile(), 
deployable), ioe);
                              } finally {
                                  removeServiced(contextName);
                              }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 95fcb7f376..eb1a0aad09 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -120,6 +120,11 @@
          Optionally allow ServiceBindingPropertySource to trim a trailing 
newline
          from a file containing a property-value. (schultz)
        </update>
+      <update>
+        Use Files.move instead of File.renameTo in the FarmWebDeployer to
+        support a broader range of environments, and to give better information
+        in the event of a failure. (schultz)
+      </update>
      </changelog>
    </subsection>
    <subsection name="Other">


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to