Преглед изворни кода

HPCC-18784 Ensure windows share translated

HPCC-18556 ensured that URL's with a windows share were
translated to Windows format so that dafilesrv's would read/write
to the correct locations.
However, remote filenames of this type also needed to translate
the URL for the purposes of IFile->queryFilename()
This was noticed as a bug in backupnode, which generated lists
of filenames based on queryFilename() and on legacy systems that
used windows share paths, a corruption was noticed.

Signed-off-by: Jake Smith <jake.smith@lexisnexisrisk.com>
Jake Smith пре 7 година
родитељ
комит
471018d1d0
2 измењених фајлова са 33 додато и 1 уклоњено
  1. 32 0
      common/remote/sockfile.cpp
  2. 1 1
      system/jlib/jfile.cpp

+ 32 - 0
common/remote/sockfile.cpp

@@ -6340,6 +6340,7 @@ static Owned<CSimpleInterface> serverThread;
 class RemoteFileTest : public CppUnit::TestFixture
 {
     CPPUNIT_TEST_SUITE(RemoteFileTest);
+        CPPUNIT_TEST(testRemoteFilename);
         CPPUNIT_TEST(testStartServer);
         CPPUNIT_TEST(testBasicFunctionality);
         CPPUNIT_TEST(testCopy);
@@ -6352,6 +6353,37 @@ class RemoteFileTest : public CppUnit::TestFixture
     size32_t testLen = 1024;
 
 protected:
+    void testRemoteFilename()
+    {
+        const char *rfns = "//1.2.3.4/dir1/file1|//1.2.3.4:7100/dir1/file1,"
+                           "//1.2.3.4:7100/dir1/file1|//1.2.3.4:7100/dir1/file1,"
+                           "//1.2.3.4/c$/dir1/file1|//1.2.3.4:7100/c$/dir1/file1,"
+                           "//1.2.3.4:7100/c$/dir1/file1|//1.2.3.4:7100/c$/dir1/file1,"
+                           "//1.2.3.4:7100/d$/dir1/file1|//1.2.3.4:7100/d$/dir1/file1";
+        StringArray tests;
+        tests.appendList(rfns, ",");
+
+        ForEachItemIn(i, tests)
+        {
+            StringArray inOut;
+            const char *pair = tests.item(i);
+            inOut.appendList(pair, "|");
+            const char *rfn = inOut.item(0);
+            const char *expected = inOut.item(1);
+            Owned<IFile> iFile = createIFile(rfn);
+            const char *res = iFile->queryFilename();
+            if (!streq(expected, res))
+            {
+                StringBuffer errMsg("testRemoteFilename MISMATCH");
+                errMsg.newline().append("Expected: ").append(expected);
+                errMsg.newline().append("Got: ").append(res);
+                PROGLOG("%s", errMsg.str());
+                CPPUNIT_ASSERT_MESSAGE(errMsg.str(), 0);
+            }
+            else
+                PROGLOG("MATCH: %s", res);
+        }
+    }
     void testStartServer()
     {
         Owned<ISocket> socket;

+ 1 - 1
system/jlib/jfile.cpp

@@ -4471,7 +4471,7 @@ StringBuffer & RemoteFilename::getRemotePath(StringBuffer & out) const
         fn = loc.append(sharehead).append(tailpath).str();
     else // try and guess from just tail (may likely fail other than for windows) 
         fn=getLocalPath(loc).str();
-    if ((c=='\\')&&(fn[1]==':')) {  // windows \\d$
+    if ((fn[1]==':') && (fn[2]=='/' || fn[2]=='\\')) {  // windows \\d$
         out.append((char)tolower(c)).append(*fn).append(getShareChar());
         fn+=2;
     }