浏览代码

Fixes #423 Allow ConfigMgr to open readonly files without crashing

Allow ConfigMgr to open readonly files without crashing. If the
file is readonly and user tries to acquire write access, display an
error message that file is readonlt. Also, alert the user if the file
being opened is corrupt (invalid xml etc.).

As a side effect, these changes have also fixed #403

Signed-off-by: Sridhar Meda <sridhar.meda@lexisnexis.com>
Sridhar Meda 13 年之前
父节点
当前提交
119f86d1d7
共有 2 个文件被更改,包括 65 次插入14 次删除
  1. 16 5
      esp/files/scripts/configmgr/navtree.js
  2. 49 9
      esp/services/WsDeploy/WsDeployService.cpp

+ 16 - 5
esp/files/scripts/configmgr/navtree.js

@@ -15,7 +15,7 @@
     allowRollup: true,
     onSuccess: function() {
       var invokeWiz = true;
-    
+
       YAHOO.util.Event.onContentReady("envctrls", function() {
         function fnce() {
           var oPushButton3 = new YAHOO.widget.Button("validatebutton", { onclick: { fn: validateEnvironment} });
@@ -29,10 +29,10 @@
 
         versionOperation(fnce, fnce);
       });
-      
+
       top.document.startWait = function(doc) { top.document.body.style.cursor = "wait"; if (doc) doc.body.style.cursor = "wait"; }
       top.document.stopWait = function(doc) { top.document.body.style.cursor = "auto"; if (doc) doc.body.style.cursor = "auto"; }
-        
+
       if (top.window.location.search.length > 0) {
         var filename = top.window.location.search.split(/=/g);
         document.forms['treeForm'].sourcefile.value = decodeURI(filename[1]);
@@ -40,7 +40,11 @@
       }
       document.getElementById('top1').style.display = 'none';
       getWaitDlg().show();
-      var params = "queryType=customType::params=environment,laststarted,lastsaved,defenvfile,username,wizops";
+      var params = "queryType=customType::params=environment,laststarted,defenvfile,username,wizops";
+
+      if (!invokeWiz)
+        params += ",lastsaved";
+
       YAHOO.util.Connect.asyncRequest('POST', '/WsDeploy/GetValue', {
         success: function(o) {
           getWaitDlg().hide();
@@ -78,6 +82,13 @@
                 handleAdvance();
             }
           }
+          else if (o.responseText.indexOf("<html") === 0) {
+            var temp = o.responseText.split(/td align=\"left\">/g);
+            var temp1 = temp[1].split(/<\/td>/g);
+            alert(temp1[0]);
+            var loc = window.location.href.split(/\?/g);
+            var newwin = top.open(loc[0], "_self");
+          }
         },
         failure: function(o) {
           getWaitDlg().hide();
@@ -4263,7 +4274,7 @@ function populateSummaryDetails(linkFlag, sumDataTable)
    },
       scope: this
    },
-   getFileName(true, !linkFlag)  + 'PrepareLinkFlag=' + true);
+   getFileName(true, true)  + 'PrepareLinkFlag=' + true);
 }
 
 

+ 49 - 9
esp/services/WsDeploy/WsDeployService.cpp

@@ -262,7 +262,7 @@ void CWsDeployExCE::init(IPropertyTree *cfg, const char *process, const char *se
 
   if (m_pCfg.get() == NULL)
     m_pCfg.setown(createPTreeFromIPT(cfg));
-  
+
   if (m_process.length() == 0)
     m_process.append(process);
 
@@ -284,7 +284,7 @@ void CWsDeployExCE::init(IPropertyTree *cfg, const char *process, const char *se
 
     m_backupDir.clear().append(m_sourceDir).append(PATHSEPSTR"backup");
   }
-  
+
   if (m_backupDir.length() == 0)
     m_backupDir.clear().append(STANDARD_CONFIG_BACKUPDIR);
 
@@ -297,6 +297,8 @@ void CWsDeployExCE::init(IPropertyTree *cfg, const char *process, const char *se
   if (pEnvFile && *pEnvFile)
   {
     CWsDeployFileInfo* fi = m_fileInfos.getValue(pEnvFile);
+    StringBuffer sb;
+
     if (!fi)
     {
       synchronized block(m_mutexSrv);
@@ -313,7 +315,7 @@ void CWsDeployExCE::init(IPropertyTree *cfg, const char *process, const char *se
       const char* psz = strrchr(pEnvFile, PATHSEPCHAR);
       if (!psz)
         psz = strrchr(pEnvFile, PATHSEPCHAR == '\\' ? '/' : '\\');
-      StringBuffer sb;
+
       if (!psz)
         sb.append(pEnvFile);
       else
@@ -321,7 +323,17 @@ void CWsDeployExCE::init(IPropertyTree *cfg, const char *process, const char *se
       m_fileInfos.setValue(sb.str(), fi);
     }
 
-    fi->initFileInfo(false);
+    try
+    {
+      fi->initFileInfo(false);
+    }
+    catch (IException* e)
+    {
+      m_fileInfos.remove(sb.str());
+      delete fi;
+      e->Release();
+    }
+
     m_envFile.append(pEnvFile);
   }
 }
@@ -553,6 +565,13 @@ bool CWsDeployFileInfo::navMenuEvent(IEspContext &context,
           StringBuffer sbName, sbUserIp;
           sbName.clear().append(req.getReqInfo().getUserId());
           context.getPeer(sbUserIp);
+
+          if (m_pFile->isReadOnly())
+          {
+            xml.appendf("Write access to the Environment cannot be provided as %s is Read Only.", m_envFile.str());
+            resp.setXmlArgs(xml.str());
+            return true;
+          }
           
           if (m_bCloud)
           {
@@ -591,7 +610,6 @@ bool CWsDeployFileInfo::navMenuEvent(IEspContext &context,
             m_keepAliveHTable.remove(sb.str());
           }
 
-
           StringBuffer sbxml;
           if (m_pFileIO.get())
           {
@@ -5775,7 +5793,7 @@ void CWsDeployFileInfo::initFileInfo(bool createOrOverwrite)
       m_lastSaved.setNow();
 
     m_pFile.setown(createIFile(m_envFile));
-    m_pFileIO.setown(m_pFile->open(IFOreadwrite));
+    m_pFileIO.setown(m_pFile->open(IFOread));
   
     {
       Owned <IPropertyTree> pTree = createPTree(*m_pFileIO);
@@ -6103,7 +6121,8 @@ bool CWsDeployExCE::onGetValue(IEspContext &context, IEspGetValueRequest &req, I
             {
               e->Release();
               //add any files already in use
-              if (getFileInfo(name.str()))
+              CWsDeployFileInfo* fi = m_fileInfos.getValue(name.str());
+              if (fi)
                 sbMultiple.append(name).append(";");
             }
           }
@@ -6323,8 +6342,18 @@ CWsDeployFileInfo* CWsDeployExCE::getFileInfo(const char* fileName, bool addIfNo
         sb.append(psz + 1);
       if (!sb.length())
         sb.append(fileName);
+
+      try
+      {
+        fi->initFileInfo(createFile);
+      }
+      catch (IException* e)
+      {
+        delete fi;
+        throw e;
+      }
+
       m_fileInfos.setValue(sb.str(), fi);
-      fi->initFileInfo(createFile);
     }
     else
       throw MakeStringException(-1, "File information not found for %s", fileName);
@@ -6335,7 +6364,18 @@ CWsDeployFileInfo* CWsDeployExCE::getFileInfo(const char* fileName, bool addIfNo
     if (fi->getUserWithLock(sbuser, sbip))
       throw MakeStringException(-1, "Cannot overwrite file '%s' as it is currently locked by user '%s' on machine '%s'", fileName, sbuser.str(), sbip.str());
     else
-      fi->initFileInfo(createFile);
+    {
+      try
+      {
+        fi->initFileInfo(createFile);
+      }
+      catch (IException* e)
+      {
+        m_fileInfos.remove(fileName);
+        delete fi;
+        throw e;
+      }
+    }
   }
 
   return fi;