You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2009/08/17 17:53:11 UTC
svn commit: r805019 -
/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBean.java
Author: robbie
Date: Mon Aug 17 15:53:10 2009
New Revision: 805019
URL: http://svn.apache.org/viewvc?rev=805019&view=rev
Log:
QPID-2042: update the save process for the access rights file. Check if the rename/move succeeds, and if not attempt a copy instead
Modified:
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBean.java
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBean.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBean.java?rev=805019&r1=805018&r2=805019&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBean.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/management/AMQUserManagementMBean.java Mon Aug 17 15:53:10 2009
@@ -27,6 +27,7 @@
import org.apache.qpid.server.management.MBeanInvocationHandlerImpl;
import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.util.FileUtils;
import org.apache.log4j.Logger;
import org.apache.commons.configuration.ConfigurationException;
@@ -439,16 +440,44 @@
// Create temporary file
File tmp = File.createTempFile(_accessFile.getName(), ".tmp");
+ tmp.deleteOnExit();
FileOutputStream output = new FileOutputStream(tmp);
_accessRights.store(output, "Generated by AMQUserManagementMBean Console : Last edited by user:" + getCurrentJMXUser());
output.close();
- // Rename new file to main file
- tmp.renameTo(_accessFile);
-
- // delete tmp
- tmp.delete();
+ // Swap temp file to main rights file.
+ File old = new File(_accessFile.getAbsoluteFile() + ".old");
+ if (old.exists())
+ {
+ old.delete();
+ }
+
+ try
+ {
+ if(!_accessFile.renameTo(old))
+ {
+ FileUtils.copyCheckedEx(_accessFile, old);
+ }
+ }
+ catch (IOException e)
+ {
+ _logger.warn("Could not backup the existing management rights file: " +e);
+ throw new IOException("Could not backup the existing management rights file: " +e);
+ }
+
+ try
+ {
+ if(!tmp.renameTo(_accessFile))
+ {
+ FileUtils.copyCheckedEx(tmp, _accessFile);
+ }
+ }
+ catch (IOException e)
+ {
+ _logger.warn("Could not copy the new management rights file into place: " +e);
+ throw new IOException("Could not copy the new management rights file into place" +e);
+ }
}
finally
{
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org