Skip to content

Commit 4b23ffe

Browse files
authored
Merge pull request #7462 from nextcloud/bugfix/reconnect-to-fpext
If File Provider Extension is unreachable, try to reconfigure client communication interface
2 parents 3c707ac + 43ea9b6 commit 4b23ffe

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/gui/macOS/fileproviderxpc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class FileProviderXPC : public QObject
3535
public:
3636
explicit FileProviderXPC(QObject *parent = nullptr);
3737

38-
[[nodiscard]] bool fileProviderExtReachable(const QString &extensionAccountId);
38+
[[nodiscard]] bool fileProviderExtReachable(const QString &extensionAccountId, bool retry = true, bool reconfigureOnFail = true);
3939

4040
// Returns enabled and set state of fast enumeration for the given extension
4141
[[nodiscard]] std::optional<std::pair<bool, bool>> fastEnumerationStateForExtension(const QString &extensionAccountId) const;

src/gui/macOS/fileproviderxpc_mac.mm

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <QLoggingCategory>
1818

1919
#include "gui/accountmanager.h"
20+
#include "gui/macOS/fileprovider.h"
2021
#include "gui/macOS/fileproviderdomainmanager.h"
2122
#include "gui/macOS/fileproviderxpc_mac_utils.h"
2223

@@ -144,17 +145,20 @@
144145
}
145146
}
146147

147-
bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId)
148-
{
148+
bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId, const bool retry, const bool reconfigureOnFail)
149149
const auto lastUnreachableTime = _unreachableAccountExtensions.value(extensionAccountId);
150-
if (lastUnreachableTime.isValid() && lastUnreachableTime.secsTo(QDateTime::currentDateTime()) < ::reachableRetryTimeout) {
150+
if (!retry
151+
&& !reconfigureOnFail
152+
&& lastUnreachableTime.isValid()
153+
&& lastUnreachableTime.secsTo(QDateTime::currentDateTime()) < ::reachableRetryTimeout) {
151154
qCInfo(lcFileProviderXPC) << "File provider extension was unreachable less than a minute ago. "
152155
<< "Not checking again";
153156
return false;
154157
}
155158

156159
const auto service = (NSObject<ClientCommunicationProtocol> *)_clientCommServices.value(extensionAccountId);
157160
if (service == nil) {
161+
qCWarning(lcFileProviderXPC) << "Could not get service for extension" << extensionAccountId;
158162
return false;
159163
}
160164

@@ -170,7 +174,27 @@
170174
_unreachableAccountExtensions.remove(extensionAccountId);
171175
} else {
172176
qCWarning(lcFileProviderXPC) << "Could not reach file provider extension.";
173-
_unreachableAccountExtensions.insert(extensionAccountId, QDateTime::currentDateTime());
177+
178+
if (reconfigureOnFail) {
179+
qCWarning(lcFileProviderXPC) << "Could not reach extension"
180+
<< extensionAccountId
181+
<< "going to attempt reconfiguring interface";
182+
const auto ncDomainManager = FileProvider::instance()->domainManager();
183+
const auto accountState = ncDomainManager->accountStateFromFileProviderDomainIdentifier(extensionAccountId);
184+
const auto domain = (NSFileProviderDomain *)(ncDomainManager->domainForAccount(accountState.get()));
185+
const auto manager = [NSFileProviderManager managerForDomain:domain];
186+
const auto fpServices = FileProviderXPCUtils::getFileProviderServices(@[manager]);
187+
const auto connections = FileProviderXPCUtils::connectToFileProviderServices(fpServices);
188+
const auto services = FileProviderXPCUtils::processClientCommunicationConnections(connections);
189+
_clientCommServices.insert(services);
190+
}
191+
192+
if (retry) {
193+
qCWarning(lcFileProviderXPC) << "Could not reach extension" << extensionAccountId << "retrying";
194+
return fileProviderExtReachable(extensionAccountId, false, false);
195+
} else {
196+
_unreachableAccountExtensions.insert(extensionAccountId, QDateTime::currentDateTime());
197+
}
174198
}
175199
return response;
176200
}

0 commit comments

Comments
 (0)