diff options
author | mharmsen <mharmsen@c9f7a03b-bd48-0410-a16d-cbbf54688b0b> | 2009-02-12 18:35:32 +0000 |
---|---|---|
committer | mharmsen <mharmsen@c9f7a03b-bd48-0410-a16d-cbbf54688b0b> | 2009-02-12 18:35:32 +0000 |
commit | 7afb54c93ae56ea4bf09fc5012045b4e7c19a9ec (patch) | |
tree | 5dafd62821ed01a6d5540b5b9b02f3f19677f7a7 /pki/base/common/src/com/netscape/cms/servlet/base/CMSStartServlet.java | |
parent | 7315a95377ee364d8f14c68ef4a469fc7dae743d (diff) | |
download | pki-7afb54c93ae56ea4bf09fc5012045b4e7c19a9ec.tar.gz pki-7afb54c93ae56ea4bf09fc5012045b4e7c19a9ec.tar.xz pki-7afb54c93ae56ea4bf09fc5012045b4e7c19a9ec.zip |
Bugzilla Bug #467155 - Change "renameTo" to "cp -p ".
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@225 c9f7a03b-bd48-0410-a16d-cbbf54688b0b
Diffstat (limited to 'pki/base/common/src/com/netscape/cms/servlet/base/CMSStartServlet.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cms/servlet/base/CMSStartServlet.java | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/pki/base/common/src/com/netscape/cms/servlet/base/CMSStartServlet.java b/pki/base/common/src/com/netscape/cms/servlet/base/CMSStartServlet.java index efb84e3fe..d28543a9c 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/base/CMSStartServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/base/CMSStartServlet.java @@ -26,6 +26,7 @@ import javax.servlet.*; import javax.servlet.http.*; import com.netscape.certsrv.apps.*; import com.netscape.certsrv.base.*; +import com.netscape.cmsutil.util.Utils; /** @@ -50,27 +51,33 @@ public class CMSStartServlet extends HttpServlet { } File f1 = new File(old_path); if (f1.exists()) { - boolean success = f1.renameTo(f); - if (!success) { - String cmds[] = new String[3]; - if (File.separator.equals("\\")) { - cmds[0] = "cmd"; - cmds[1] = "/c"; - cmds[2] = "copy "+ - f1.getAbsolutePath().replace('/', '\\') + " " + - f.getAbsolutePath().replace('/', '\\'); + // The following block of code moves "CMS.cfg" to "CS.cfg". + try { + if( Utils.isNT() ) { + // NT is very picky on the path + Utils.exec( "copy " + + f1.getAbsolutePath().replace( '/', '\\' ) + + " " + + f.getAbsolutePath().replace( '/', '\\' ) ); } else { - cmds[0] = "/bin/sh"; - cmds[1] = "-c"; - cmds[2] = "cp " + f1.getAbsolutePath() + " " + - f.getAbsolutePath(); + // Create a copy of the original file which + // preserves the original file permissions. + Utils.exec( "cp -p " + f1.getAbsolutePath() + " " + + f.getAbsolutePath() ); } - try { - Process process = Runtime.getRuntime().exec(cmds); - process.waitFor(); - } catch (Exception e) { + // Remove the original file if and only if + // the backup copy was successful. + if( f.exists() ) { + f1.delete(); + + // Make certain that the new file has + // the correct permissions. + if( !Utils.isNT() ) { + Utils.exec( "chmod 00660 " + f.getAbsolutePath() ); + } } + } catch (Exception e) { } } } |