Jelajahi Sumber

HPCC-9802 Delete logical file using removeEntry(), not detach()

Existing ECLWatch code deletes a logical file using detach(). When
the file is associated with a superfile, the superfile may not be
able to be deleted. This fix calls removeEntry() to delete a file.
The removeEntry() should check whether the file can be deleted or
not if it is a subfile. This fix also cleans the code.

Signed-off-by: Kevin Wang <kevin.wang@lexisnexis.com>
Kevin Wang 12 tahun lalu
induk
melakukan
2276b3d89b
2 mengubah file dengan 37 tambahan dan 44 penghapusan
  1. 23 37
      esp/services/ws_dfu/ws_dfuService.cpp
  2. 14 7
      esp/smc/SMCLib/LogicFileWrapper.cpp

+ 23 - 37
esp/services/ws_dfu/ws_dfuService.cpp

@@ -1158,23 +1158,35 @@ bool CWsDfuEx::DFUDeleteFiles(IEspContext &context, IEspDFUArrayActionRequest &r
 
             if (j>0)
             { // 2nd pass, now we want to skip superfiles and the files which cannot do the lookup.
-
-                if (superFileNames.contains(filename))
-                    continue;
-
-                if (filesCannotBeDeleted.contains(filename))
+                if (superFileNames.contains(filename) || filesCannotBeDeleted.contains(filename))
                     continue;
             }
 
-            Owned<IDistributedFile> df;
             try
             {
-                df.setown(queryDistributedFileDirectory().lookup(filename, userdesc, true));
-                if(!df)
+                IDistributedFileDirectory &fdir = queryDistributedFileDirectory();
                 {
-                    returnStr.appendf("<Message><Value>Cannot delete %s: file not found</Value></Message>", filename);
-                    filesCannotBeDeleted.append(filename);
-                    continue;
+                    Owned<IDistributedFile> df = fdir.lookup(filename, userdesc, true);
+                    if(!df)
+                    {
+                        returnStr.appendf("<Message><Value>Cannot delete %s: file not found</Value></Message>", filename);
+                        filesCannotBeDeleted.append(filename);
+                        continue;
+                    }
+                    if (0==j) // skip non-super files on 1st pass
+                    {
+                        if(!df->querySuperFile())
+                            continue;
+
+                        superFileNames.append(filename);
+                    }
+                }
+                if (!fdir.removeEntry(filename, userdesc, NULL, REMOVE_FILE_SDS_CONNECT_TIMEOUT))
+                    returnStr.appendf("<Message><Value>Failed to delete %s</Value></Message>", filename);
+                else
+                {
+                    PROGLOG("Deleted Logical File: %s by: %s\n",filename, username.str());
+                    returnStr.appendf("<Message><Value>Deleted File %s</Value></Message>", filename);
                 }
             }
             catch(IException* e)
@@ -1192,32 +1204,6 @@ bool CWsDfuEx::DFUDeleteFiles(IEspContext &context, IEspDFUArrayActionRequest &r
             {
                 returnStr.appendf("<Message><Value>Cannot delete %s: unknown exception.</Value></Message>", filename);
             }
-            if (df)
-            {
-                if (0==j) // skip non-super files on 1st pass
-                {
-                    if(!df->querySuperFile())
-                        continue;
-
-                    superFileNames.append(filename);
-                }
-
-                DBGLOG("CWsDfuEx::DFUDeleteFiles User=%s Action=Delete File=%s",username.str(), filename);
-                try
-                {
-                    df->detach(REMOVE_FILE_SDS_CONNECT_TIMEOUT);
-                    PROGLOG("Deleted Logical File: %s\n",filename);
-                    returnStr.appendf("<Message><Value>Deleted File %s</Value></Message>", filename);
-                }
-                catch (IException *e)
-                {
-                    StringBuffer errorMsg;
-                    e->errorMessage(errorMsg);
-                    PROGLOG("%s", errorMsg.str());
-                    e->Release();
-                    returnStr.appendf("<Message><Value>%s</Value></Message>", errorMsg.str());
-                }
-            }
         }
     }
 

+ 14 - 7
esp/smc/SMCLib/LogicFileWrapper.cpp

@@ -67,16 +67,23 @@ bool LogicFileWrapper::doDeleteFile(const char* logicalName,const char *cluster,
 
     try
     {
-        Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(cname.str(), udesc, true) ;
-        if(!df)
+        IDistributedFileDirectory &fdir = queryDistributedFileDirectory();
         {
-            returnStr.appendf("<Message><Value>File %s not found</Value></Message>", cname.str());
-            return false;
+            Owned<IDistributedFile> df = fdir.lookup(cname.str(), udesc, true) ;
+            if(!df)
+            {
+                returnStr.appendf("<Message><Value>File %s not found</Value></Message>", cname.str());
+                return false;
+            }
         }
 
-        df->detach();
-        returnStr.appendf("<Message><Value>Deleted File %s</Value></Message>", cname.str());
-        DBGLOG("%s", returnStr.str());
+        if (!fdir.removeEntry(cname.str(), udesc))
+            returnStr.appendf("<Message><Value>Failed to delete %s</Value></Message>", cname.str());
+        else
+        {
+            returnStr.appendf("<Message><Value>Deleted File %s</Value></Message>", cname.str());
+            DBGLOG("%s", returnStr.str());
+        }
         return true;
     }
     catch (IException *e)