瀏覽代碼

HPCC-13495 Revise based on code review

1. Simplify code using isLocal()
2. Call getCache() since cache is built
3. Switch one ' to \" since it is the xpath being cached.

Signed-off-by: wangkx <kevin.wang@lexisnexis.com>
wangkx 10 年之前
父節點
當前提交
63083ca5ed
共有 2 個文件被更改,包括 14 次插入55 次删除
  1. 11 52
      common/environment/environment.cpp
  2. 3 3
      esp/services/ws_fs/ws_fsService.cpp

+ 11 - 52
common/environment/environment.cpp

@@ -980,9 +980,6 @@ IConstDomainInfo * CLocalEnvironment::getDomain(const char * name) const
 
 void CLocalEnvironment::buildMachineCache() const
 {
-    StringBuffer localHostIP;
-    queryHostIP().getIpText(localHostIP);
-
     synchronized procedure(safeCache);
     if (!machineCacheBuilt)
     {
@@ -1004,8 +1001,11 @@ void CLocalEnvironment::buildMachineCache() const
                 x.append(name).append("\"]");
                 Owned<IConstEnvBase> cached = new CConstMachineInfo((CLocalEnvironment *) this, &it->query());
                 cache.setValue(x.str(), cached);
-                if (streq(".", name) || strieq("localhost", name) || streq("127.0.0.1", name) || streq(name, localHostIP.str()))
-                    cache.setValue("Hardware/Computer[@netAddress='.']", cached);
+
+                IpAddress ip;
+                ip.ipset(name);
+                if (ip.isLocal())
+                    cache.setValue("Hardware/Computer[@netAddress=\".\"]", cached);
             }
         }
         machineCacheBuilt = true;
@@ -1128,32 +1128,9 @@ IConstMachineInfo * CLocalEnvironment::getMachineByAddress(const char * name) co
 
 IConstMachineInfo * CLocalEnvironment::getMachineForLocalHost() const
 {
-    IConstEnvBase *cached = getCache("Hardware/Computer[@netAddress='.']");
-    if (!cached)
-    {
-        StringBuffer localHostIP;
-        queryHostIP().getIpText(localHostIP);
-
-        StringArray possibleIPs;
-        possibleIPs.append(".");
-        possibleIPs.append("localhost");
-        possibleIPs.append("127.0.0.1");
-        possibleIPs.append(localHostIP.str());
-
-        synchronized procedure(safeCache);
-        ForEachItemIn(i, possibleIPs)
-        {
-            VStringBuffer xpath("Hardware/Computer[@netAddress='%s']", possibleIPs.item(i));
-            IPropertyTree *d = p->queryPropTree(xpath.str());
-            if (d)
-            {
-                cached = new CConstMachineInfo((CLocalEnvironment *) this, d);
-                setCache("Hardware/Computer[@netAddress='.']", cached);
-                break;
-            }
-        }
-    }
-    return (CConstMachineInfo *) cached;
+    buildMachineCache();
+    synchronized procedure(safeCache);
+    return (CConstMachineInfo *) getCache("Hardware/Computer[@netAddress=\".\"]");
 }
 
 IConstDropZoneInfo * CLocalEnvironment::getDropZone(const char * name) const
@@ -1163,16 +1140,7 @@ IConstDropZoneInfo * CLocalEnvironment::getDropZone(const char * name) const
     buildDropZoneCache();
     VStringBuffer xpath("Software/DropZone[@name=\"%s\"]", name);
     synchronized procedure(safeCache);
-    IConstEnvBase *cached = getCache(xpath.str());
-    if (!cached)
-    {
-        IPropertyTree *d = p->queryPropTree(xpath.str());
-        if (!d)
-            return NULL;
-        cached = new CConstDropZoneInfo((CLocalEnvironment *) this, d);
-        setCache(xpath.str(), cached);
-    }
-    return (CConstDropZoneInfo *) cached;
+    return (CConstDropZoneInfo *) getCache(xpath.str());
 }
 
 
@@ -1181,18 +1149,9 @@ IConstDropZoneInfo * CLocalEnvironment::getDropZoneByComputer(const char * compu
     if (!computer)
         return NULL;
     buildDropZoneCache();
-    VStringBuffer xpath("Software/DropZone[@computer='%s']", computer);
+    VStringBuffer xpath("Software/DropZone[@computer=\"%s\"]", computer);
     synchronized procedure(safeCache);
-    IConstEnvBase *cached = getCache(xpath.str());
-    if (!cached)
-    {
-        IPropertyTree *d = p->queryPropTree(xpath.str());
-        if (!d)
-            return NULL;
-        cached = new CConstDropZoneInfo((CLocalEnvironment *) this, d);
-        setCache(xpath.str(), cached);
-    }
-    return (CConstDropZoneInfo *) cached;
+    return (CConstDropZoneInfo *) getCache(xpath.str());
 }
 
 IConstInstanceInfo * CLocalEnvironment::getInstance(const char *type, const char *version, const char *domain) const

+ 3 - 3
esp/services/ws_fs/ws_fsService.cpp

@@ -2291,9 +2291,9 @@ const char* CFileSprayEx::getDropZoneDirByIP(const char* ip, StringBuffer& dir)
     Owned<IConstMachineInfo> machine = env->getMachineByAddress(ip);
     if (!machine)
     {
-        StringBuffer localHostIP;
-        queryHostIP().getIpText(localHostIP);
-        if (!strieq(".", ip) && !strieq("localhost", ip) && !strieq("127.0.0.1", ip) && !strieq(ip, localHostIP.str()))
+        IpAddress ipAddr;
+        ipAddr.ipset(ip);
+        if (!ipAddr.isLocal())
             return NULL;
         machine.setown(env->getMachineForLocalHost());
         if (!machine)