[Pkg-owncloud-commits] [owncloud-client] 81/211: Windows Shell Integration: try to wait for connection

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Oct 25 09:10:29 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit e66ca267f4795ee9c86454d06c3b90a9d021329f
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Wed Oct 15 15:13:04 2014 +0200

    Windows Shell Integration: try to wait for connection
---
 .../OCUtil/CommunicationSocket.cpp                 | 16 +++---
 .../OCShellExtensions/OCUtil/CommunicationSocket.h |  3 +-
 .../OCShellExtensions/OCUtil/RemotePathChecker.cpp | 60 +++++++++++++++++++---
 .../OCShellExtensions/OCUtil/RemotePathChecker.h   |  1 +
 4 files changed, 63 insertions(+), 17 deletions(-)

diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.cpp b/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.cpp
index 13494d9..82ad7ce 100644
--- a/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.cpp
+++ b/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.cpp
@@ -53,11 +53,8 @@ bool CommunicationSocket::Close()
 }
 
 
-bool CommunicationSocket::Connect()
+bool CommunicationSocket::Connect(const std::wstring &pipename)
 {
-    auto pipename = std::wstring(L"\\\\.\\pipe\\");
-    pipename += L"ownCloud";
-
 	_pipe = CreateFile(pipename.data(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
 
     if (_pipe == INVALID_HANDLE_VALUE) {
@@ -76,8 +73,8 @@ bool CommunicationSocket::SendMsg(const wchar_t* message)
     if (result) {
         return true;
     } else {
-//        qWarning() << "Failed to send data." <<;
-        // look up error code here using GetLastError()
+        Close();
+
         return false;
     }
 }
@@ -90,7 +87,10 @@ bool CommunicationSocket::ReadLine(wstring* response)
 
     response->clear();
 
-	Sleep(50);
+    if (_pipe == INVALID_HANDLE_VALUE) {
+        return false;
+    }
+
 
 	while (true) {
         int lbPos = 0;
@@ -111,7 +111,7 @@ bool CommunicationSocket::ReadLine(wstring* response)
 
         auto result = ReadFile(_pipe, resp_utf8.data(), DWORD(resp_utf8.size()), &numBytesRead, NULL);
         if (!result) {
-//            qWarning() << "Failed to read data from the pipe";
+            Close();
             return false;
         }
         if (numBytesRead <= 0) {
diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.h b/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.h
index 7e9cd11..d29d863 100644
--- a/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.h
+++ b/shell_integration/windows/OCShellExtensions/OCUtil/CommunicationSocket.h
@@ -29,7 +29,7 @@ public:
 	CommunicationSocket();
 	~CommunicationSocket();
 
-	bool Connect();
+	bool Connect(const std::wstring& pipename);
 	bool Close();
 
 	bool SendMsg(const wchar_t*);
@@ -40,6 +40,7 @@ public:
 private:	
 	HANDLE _pipe;
 	std::vector<char> _buffer;
+    bool _connected;
 };
 
 #endif
\ No newline at end of file
diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.cpp b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.cpp
index 5967245..668cf66 100644
--- a/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.cpp
+++ b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.cpp
@@ -31,14 +31,28 @@ using namespace std;
 // This code is run in a thread
 void RemotePathChecker::workerThreadLoop()
 {
+    auto pipename = std::wstring(L"\\\\.\\pipe\\");
+    pipename += L"ownCloud";
+
+    bool connected = false;
     CommunicationSocket socket;
     std::unordered_set<std::wstring> asked;
-    if (!socket.Connect()) {
-        return;
-        //FIXME! what if this fails!  what if we are disconnected later?
-    }
 
     while(!_stop) {
+
+        if (!connected) {
+            asked.clear();
+            if (!WaitNamedPipe(pipename, 5 * 1000)) {
+                continue;
+            }
+            if (!socket.Connect(pipename)) {
+                continue;
+            }
+            connected = true;
+            std::unique_lock<std::mutex> lock(_mutex);
+            _connected = true;
+        }
+
         {
             std::unique_lock<std::mutex> lock(_mutex);
             while (!_pending.empty() && !_stop) {
@@ -59,8 +73,28 @@ void RemotePathChecker::workerThreadLoop()
             if (StringUtil::begins_with(response, wstring(L"REGISTER_PATH:"))) {
                 wstring responsePath = response.substr(14); // length of REGISTER_PATH:
 
-                std::unique_lock<std::mutex> lock(_mutex);
-                _watchedDirectories.push_back(responsePath);
+                {   std::unique_lock<std::mutex> lock(_mutex);
+                    _watchedDirectories.push_back(responsePath);
+                }
+                SHChangeNotify(SHCNE_MKDIR, SHCNF_PATH, responsePath.data(), NULL);
+            if (StringUtil::begins_with(response, wstring(L"UNREGISTER_PATH:"))) {
+                wstring responsePath = response.substr(16); // length of UNREGISTER_PATH:
+
+                {   std::unique_lock<std::mutex> lock(_mutex);
+                    _watchedDirectories.erase(
+                        std::remove(_watchedDirectories.begin(), _watchedDirectories.end(), responsePath),
+                        _watchedDirectories.end());
+
+                    // Remove any item from the cache
+                    for (auto it = _cache.begin(); it != _cache.end() ; ) {
+                        if (StringUtil::begins_with(it.first, responsePath)) {
+                            it = _cache.erase(it);
+                        } else {
+                            ++it;
+                        }
+                    }
+                }
+                SHChangeNotify(SHCNE_MKDIR, SHCNF_PATH, responsePath.data(), NULL);
             } else if (StringUtil::begins_with(response, wstring(L"STATUS:")) ||
                     StringUtil::begins_with(response, wstring(L"BROADCAST:"))) {
 
@@ -85,8 +119,14 @@ void RemotePathChecker::workerThreadLoop()
             }
         }
 
-        if (_stop)
-            return;
+        if (socket.Event() == INVALID_HANDLE_VALUE) {
+            std::unique_lock<std::mutex> lock(_mutex);
+            _cache.clear();
+            _watchedDirectories.clear();
+            _connected = connected = false;
+        }
+
+        Sleep(50);
     }
 }
 
@@ -94,6 +134,7 @@ void RemotePathChecker::workerThreadLoop()
 
 RemotePathChecker::RemotePathChecker()
     : _thread([this]{ this->workerThreadLoop(); } )
+    , _connected(false)
     , _newQueries(CreateEvent(NULL, true, true, NULL))
 {
 }
@@ -118,6 +159,9 @@ bool RemotePathChecker::IsMonitoredPath(const wchar_t* filePath, int* state)
     assert(state); assert(filePath);
 
     std::unique_lock<std::mutex> lock(_mutex);
+    if (!_connected) {
+        return false;
+    }
 
     auto path = std::wstring(filePath);
 
diff --git a/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.h b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.h
index 5c4c43f..0aa05fd 100644
--- a/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.h
+++ b/shell_integration/windows/OCShellExtensions/OCUtil/RemotePathChecker.h
@@ -54,6 +54,7 @@ private:
 
     std::unordered_map<std::wstring, FileState> _cache;
     std::vector<std::wstring> _watchedDirectories;
+    bool _connected;
 
 
     // The main thread notifies when there are new items in _pending

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list