Browse Source

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 years ago
parent
commit
119f86d1d7
2 changed files with 65 additions and 14 deletions
  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,
     allowRollup: true,
     onSuccess: function() {
     onSuccess: function() {
       var invokeWiz = true;
       var invokeWiz = true;
-    
+
       YAHOO.util.Event.onContentReady("envctrls", function() {
       YAHOO.util.Event.onContentReady("envctrls", function() {
         function fnce() {
         function fnce() {
           var oPushButton3 = new YAHOO.widget.Button("validatebutton", { onclick: { fn: validateEnvironment} });
           var oPushButton3 = new YAHOO.widget.Button("validatebutton", { onclick: { fn: validateEnvironment} });
@@ -29,10 +29,10 @@
 
 
         versionOperation(fnce, fnce);
         versionOperation(fnce, fnce);
       });
       });
-      
+
       top.document.startWait = function(doc) { top.document.body.style.cursor = "wait"; if (doc) doc.body.style.cursor = "wait"; }
       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"; }
       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) {
       if (top.window.location.search.length > 0) {
         var filename = top.window.location.search.split(/=/g);
         var filename = top.window.location.search.split(/=/g);
         document.forms['treeForm'].sourcefile.value = decodeURI(filename[1]);
         document.forms['treeForm'].sourcefile.value = decodeURI(filename[1]);
@@ -40,7 +40,11 @@
       }
       }
       document.getElementById('top1').style.display = 'none';
       document.getElementById('top1').style.display = 'none';
       getWaitDlg().show();
       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', {
       YAHOO.util.Connect.asyncRequest('POST', '/WsDeploy/GetValue', {
         success: function(o) {
         success: function(o) {
           getWaitDlg().hide();
           getWaitDlg().hide();
@@ -78,6 +82,13 @@
                 handleAdvance();
                 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) {
         failure: function(o) {
           getWaitDlg().hide();
           getWaitDlg().hide();
@@ -4263,7 +4274,7 @@ function populateSummaryDetails(linkFlag, sumDataTable)
    },
    },
       scope: this
       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)
   if (m_pCfg.get() == NULL)
     m_pCfg.setown(createPTreeFromIPT(cfg));
     m_pCfg.setown(createPTreeFromIPT(cfg));
-  
+
   if (m_process.length() == 0)
   if (m_process.length() == 0)
     m_process.append(process);
     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");
     m_backupDir.clear().append(m_sourceDir).append(PATHSEPSTR"backup");
   }
   }
-  
+
   if (m_backupDir.length() == 0)
   if (m_backupDir.length() == 0)
     m_backupDir.clear().append(STANDARD_CONFIG_BACKUPDIR);
     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)
   if (pEnvFile && *pEnvFile)
   {
   {
     CWsDeployFileInfo* fi = m_fileInfos.getValue(pEnvFile);
     CWsDeployFileInfo* fi = m_fileInfos.getValue(pEnvFile);
+    StringBuffer sb;
+
     if (!fi)
     if (!fi)
     {
     {
       synchronized block(m_mutexSrv);
       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);
       const char* psz = strrchr(pEnvFile, PATHSEPCHAR);
       if (!psz)
       if (!psz)
         psz = strrchr(pEnvFile, PATHSEPCHAR == '\\' ? '/' : '\\');
         psz = strrchr(pEnvFile, PATHSEPCHAR == '\\' ? '/' : '\\');
-      StringBuffer sb;
+
       if (!psz)
       if (!psz)
         sb.append(pEnvFile);
         sb.append(pEnvFile);
       else
       else
@@ -321,7 +323,17 @@ void CWsDeployExCE::init(IPropertyTree *cfg, const char *process, const char *se
       m_fileInfos.setValue(sb.str(), fi);
       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);
     m_envFile.append(pEnvFile);
   }
   }
 }
 }
@@ -553,6 +565,13 @@ bool CWsDeployFileInfo::navMenuEvent(IEspContext &context,
           StringBuffer sbName, sbUserIp;
           StringBuffer sbName, sbUserIp;
           sbName.clear().append(req.getReqInfo().getUserId());
           sbName.clear().append(req.getReqInfo().getUserId());
           context.getPeer(sbUserIp);
           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)
           if (m_bCloud)
           {
           {
@@ -591,7 +610,6 @@ bool CWsDeployFileInfo::navMenuEvent(IEspContext &context,
             m_keepAliveHTable.remove(sb.str());
             m_keepAliveHTable.remove(sb.str());
           }
           }
 
 
-
           StringBuffer sbxml;
           StringBuffer sbxml;
           if (m_pFileIO.get())
           if (m_pFileIO.get())
           {
           {
@@ -5775,7 +5793,7 @@ void CWsDeployFileInfo::initFileInfo(bool createOrOverwrite)
       m_lastSaved.setNow();
       m_lastSaved.setNow();
 
 
     m_pFile.setown(createIFile(m_envFile));
     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);
       Owned <IPropertyTree> pTree = createPTree(*m_pFileIO);
@@ -6103,7 +6121,8 @@ bool CWsDeployExCE::onGetValue(IEspContext &context, IEspGetValueRequest &req, I
             {
             {
               e->Release();
               e->Release();
               //add any files already in use
               //add any files already in use
-              if (getFileInfo(name.str()))
+              CWsDeployFileInfo* fi = m_fileInfos.getValue(name.str());
+              if (fi)
                 sbMultiple.append(name).append(";");
                 sbMultiple.append(name).append(";");
             }
             }
           }
           }
@@ -6323,8 +6342,18 @@ CWsDeployFileInfo* CWsDeployExCE::getFileInfo(const char* fileName, bool addIfNo
         sb.append(psz + 1);
         sb.append(psz + 1);
       if (!sb.length())
       if (!sb.length())
         sb.append(fileName);
         sb.append(fileName);
+
+      try
+      {
+        fi->initFileInfo(createFile);
+      }
+      catch (IException* e)
+      {
+        delete fi;
+        throw e;
+      }
+
       m_fileInfos.setValue(sb.str(), fi);
       m_fileInfos.setValue(sb.str(), fi);
-      fi->initFileInfo(createFile);
     }
     }
     else
     else
       throw MakeStringException(-1, "File information not found for %s", fileName);
       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))
     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());
       throw MakeStringException(-1, "Cannot overwrite file '%s' as it is currently locked by user '%s' on machine '%s'", fileName, sbuser.str(), sbip.str());
     else
     else
-      fi->initFileInfo(createFile);
+    {
+      try
+      {
+        fi->initFileInfo(createFile);
+      }
+      catch (IException* e)
+      {
+        m_fileInfos.remove(fileName);
+        delete fi;
+        throw e;
+      }
+    }
   }
   }
 
 
   return fi;
   return fi;