[Libreoffice-commits] online.git: loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp

Henry Castro hcastro at collabora.com
Fri Jul 17 13:57:02 PDT 2015


 loolwsd/LOOLSession.cpp |   47 +++++++++++++++++--------
 loolwsd/LOOLWSD.cpp     |   90 ------------------------------------------------
 2 files changed, 32 insertions(+), 105 deletions(-)

New commits:
commit 404b5edbc96521e2911d542696274e8c42691db6
Author: Henry Castro <hcastro at collabora.com>
Date:   Fri Jul 17 16:55:49 2015 -0400

    loolwsd: FileTransferHandler no longer need it.

diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 502010a..000b319 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -504,29 +504,46 @@ void MasterProcessSession::dispatchChild()
 
     if (!aUri.empty() && aUri.getScheme() == "file")
     {
-        // The process is jail rooted, so it requests loolMain process to transfer files.
+        Path aSrcFile(aUri.getPath());
+        Path aDstFile(Path(getJailPath(childSession->_childId), jailDocumentURL.substr(1)), aSrcFile.getFileName());
+        Path aDstPath(getJailPath(childSession->_childId), jailDocumentURL.substr(1));
+        Path aJailFile(jailDocumentURL, aSrcFile.getFileName());
+
         try
         {
-            Path aSrcFile(aUri.getPath());
-            Path aDstFile(Path(getJailPath(childSession->_childId), jailDocumentURL.substr(1)), aSrcFile.getFileName());
-            std::string sCopy(aSrcFile.toString() + " " + aDstFile.toString());
-            std::string str;
-
-            DialogSocket ds;
-            ds.connect(SocketAddress("127.0.0.1", LOOLWSD::FILE_PORT_NUMBER));
-            ds.sendMessage(sCopy);
-            ds.receiveMessage(str);
-
-            if (str != "OK")
-                Application::instance().logger().error( Util::logPrefix() +
-                    "DataSocket copyTo(\"" + aSrcFile.toString() + "\",\"" + aDstFile.toString() + "\") failed: " + str);
+            File(aDstPath).createDirectories();
         }
         catch (Exception& exc)
         {
             Application::instance().logger().error( Util::logPrefix() +
-                "FileTransferHanlder failed: " + exc.displayText());
+                "createDirectories(\"" + aDstPath.toString() + "\") failed: " + exc.displayText() );
+
+        }
+
+#ifdef __linux
+        Application::instance().logger().information(Util::logPrefix() + "Linking " + aSrcFile.toString() + " to " + aDstFile.toString());
+        if (link(aSrcFile.toString().c_str(), aDstFile.toString().c_str()) == -1)
+        {
+            // Failed
+            Application::instance().logger().error( Util::logPrefix() +
+                "link(\"" + aSrcFile.toString() + "\",\"" + aDstFile.toString() + "\") failed: " + strerror(errno) );
         }
+#endif
 
+        try
+        {
+            //fallback
+            if (!File(aDstFile).exists())
+            {
+                Application::instance().logger().information(Util::logPrefix() + "Copying " + aSrcFile.toString() + " to " + aDstFile.toString());
+                File(aSrcFile).copyTo(aDstFile.toString());
+            }
+        }
+        catch (Exception& exc)
+        {
+            Application::instance().logger().error( Util::logPrefix() +
+                "copyTo(\"" + aSrcFile.toString() + "\",\"" + aDstFile.toString() + "\") failed: " + exc.displayText());
+        }
     }
 
     _peer = childSession;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 595f955..76d4a73 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -411,92 +411,6 @@ private:
     HTTPServer& _srv;
 };
 
-class FileTransferHandler : public Runnable
-{
-public:
-    FileTransferHandler() : _socket(ServerSocket(LOOLWSD::FILE_PORT_NUMBER))
-    {
-    }
-
-    void run() override
-    {
-        Poco::Timespan span(250000);
-
-        while (true)
-        {
-            if (_socket.poll(span, Socket::SELECT_READ))
-            {
-                DialogSocket ds = _socket.acceptConnection();
-
-                try
-                {
-                    std::string command;
-                    while (ds.receiveMessage(command))
-                    {
-                        FastMutex::ScopedLock lock(_mutex);
-                        ds.sendMessage(transferFile(command));
-                    }
-                }
-				catch (Poco::Exception& exc)
-				{
-					std::cerr << "FileTransferHandler: " << exc.displayText() << std::endl;
-				}
-            }
-        }
-    }
-
-    std::string transferFile(std::string command)
-    {
-        StringTokenizer tokens(command, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
-        if ( tokens.count() != 2 )
-            return "Souce and Destination is needed :" + command;
-
-        Path aSrcFile(tokens[0]);
-        Path aDstFile(tokens[1]);
-        Path aDstPath(aDstFile.parent());
-
-        try
-        {
-            File(aDstPath).createDirectories();
-        }
-        catch (Exception& exc)
-        {
-            return exc.displayText();
-        }
-
-#ifdef __linux
-        Application::instance().logger().information(Util::logPrefix() + "Linking " + aSrcFile.toString() + " to " + aDstFile.toString());
-        if (link(aSrcFile.toString().c_str(), aDstFile.toString().c_str()) == -1)
-        {
-            // Failed
-            Application::instance().logger().error( Util::logPrefix() +
-                "link(\"" + aSrcFile.toString() + "\",\"" + aDstFile.toString() + "\") failed: " + strerror(errno) );
-        }
-#endif
-
-        try
-        {
-            //fallback
-            if (!File(aDstFile).exists())
-            {
-                Application::instance().logger().information(Util::logPrefix() + "Copying " + aSrcFile.toString() + " to " + aDstFile.toString());
-                File(aSrcFile).copyTo(aDstFile.toString());
-            }
-        }
-        catch (Exception& exc)
-        {
-            return exc.displayText();
-        }
-
-        return "OK";
-    }
-
-private:
-	Poco::Net::ServerSocket  _socket;
-    mutable Poco::FastMutex  _mutex;
-};
-
-
 int LOOLWSD::portNumber = DEFAULT_CLIENT_PORT_NUMBER;
 std::string LOOLWSD::cache = LOOLWSD_CACHEDIR;
 std::string LOOLWSD::sysTemplate;
@@ -1118,10 +1032,6 @@ void LOOLWSD::loolMain()
 
     namedMutexLOOL.unlock();
 
-    Thread threadFile;
-    FileTransferHandler svrFile;
-    threadFile.start(svrFile);
-
     while (MasterProcessSession::_childProcesses.size() > 0)
     {
         int status;


More information about the Libreoffice-commits mailing list