mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Only disconnect if connected
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com> Signed-off-by: Hannah von Reth <h.vonreth@opencloud.eu>
This commit is contained in:
parent
4d2966771d
commit
cfbc1e8703
@ -478,10 +478,6 @@ CF_SET_PIN_FLAGS pinRecurseModeToCfSetPinFlags(OCC::CfApiWrapper::SetPinRecurseM
|
||||
}
|
||||
}
|
||||
|
||||
OCC::CfApiWrapper::ConnectionKey::ConnectionKey()
|
||||
: _data(new CF_CONNECTION_KEY, [](void *p) { delete reinterpret_cast<CF_CONNECTION_KEY *>(p); })
|
||||
{
|
||||
}
|
||||
|
||||
OCC::CfApiWrapper::FileHandle::FileHandle()
|
||||
: _data(nullptr, [](void *) {})
|
||||
@ -722,15 +718,12 @@ OCC::Result<void, QString> OCC::CfApiWrapper::unregisterSyncRoot(const QString &
|
||||
}
|
||||
}
|
||||
|
||||
OCC::Result<OCC::CfApiWrapper::ConnectionKey, QString> OCC::CfApiWrapper::connectSyncRoot(const QString &path, OCC::VfsCfApi *context)
|
||||
OCC::Result<CF_CONNECTION_KEY, QString> OCC::CfApiWrapper::connectSyncRoot(const QString &path, OCC::VfsCfApi *context)
|
||||
{
|
||||
auto key = ConnectionKey();
|
||||
CF_CONNECTION_KEY key;
|
||||
const auto p = path.toStdWString();
|
||||
const qint64 result = CfConnectSyncRoot(p.data(),
|
||||
cfApiCallbacks,
|
||||
context,
|
||||
CF_CONNECT_FLAG_REQUIRE_PROCESS_INFO | CF_CONNECT_FLAG_REQUIRE_FULL_FILE_PATH | CF_CONNECT_FLAG_BLOCK_SELF_IMPLICIT_HYDRATION,
|
||||
static_cast<CF_CONNECTION_KEY *>(key.get()));
|
||||
const qint64 result =
|
||||
CfConnectSyncRoot(p.data(), cfApiCallbacks, context, CF_CONNECT_FLAG_REQUIRE_PROCESS_INFO | CF_CONNECT_FLAG_REQUIRE_FULL_FILE_PATH | CF_CONNECT_FLAG_BLOCK_SELF_IMPLICIT_HYDRATION, &key);
|
||||
Q_ASSERT(result == S_OK);
|
||||
if (result != S_OK) {
|
||||
return QString::fromWCharArray(_com_error(result).ErrorMessage());
|
||||
@ -739,12 +732,13 @@ OCC::Result<OCC::CfApiWrapper::ConnectionKey, QString> OCC::CfApiWrapper::connec
|
||||
}
|
||||
}
|
||||
|
||||
OCC::Result<void, QString> OCC::CfApiWrapper::disconnectSyncRoot(ConnectionKey &&key)
|
||||
OCC::Result<void, QString> OCC::CfApiWrapper::disconnectSyncRoot(CF_CONNECTION_KEY &&key)
|
||||
{
|
||||
const qint64 result = CfDisconnectSyncRoot(*static_cast<CF_CONNECTION_KEY *>(key.get()));
|
||||
Q_ASSERT(result == S_OK);
|
||||
const qint64 result = CfDisconnectSyncRoot(key);
|
||||
if (result != S_OK) {
|
||||
return QString::fromWCharArray(_com_error(result).ErrorMessage());
|
||||
qCWarning(lcCfApiWrapper) << "Disconnecting sync root failed" << OCC::Utility::formatWinError(result);
|
||||
Q_ASSERT(result == S_OK);
|
||||
return OCC::Utility::formatWinError(result);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -72,8 +72,8 @@ NEXTCLOUD_CFAPI_EXPORT Result<void, QString> registerSyncRoot(const QString &pat
|
||||
NEXTCLOUD_CFAPI_EXPORT void unregisterSyncRootShellExtensions(const QString &providerName, const QString &folderAlias, const QString &accountDisplayName);
|
||||
NEXTCLOUD_CFAPI_EXPORT Result<void, QString> unregisterSyncRoot(const QString &path, const QString &providerName, const QString &accountDisplayName);
|
||||
|
||||
NEXTCLOUD_CFAPI_EXPORT Result<ConnectionKey, QString> connectSyncRoot(const QString &path, VfsCfApi *context);
|
||||
NEXTCLOUD_CFAPI_EXPORT Result<void, QString> disconnectSyncRoot(ConnectionKey &&key);
|
||||
Result<CF_CONNECTION_KEY, QString> connectSyncRoot(const QString &path, VfsCfApi *context);
|
||||
Result<void, QString> disconnectSyncRoot(CF_CONNECTION_KEY &&key);
|
||||
NEXTCLOUD_CFAPI_EXPORT bool isAnySyncRoot(const QString &providerName, const QString &accountDisplayName);
|
||||
|
||||
NEXTCLOUD_CFAPI_EXPORT bool isSparseFile(const QString &path);
|
||||
|
||||
@ -103,7 +103,7 @@ class VfsCfApiPrivate
|
||||
{
|
||||
public:
|
||||
QList<HydrationJob *> hydrationJobs;
|
||||
cfapi::ConnectionKey connectionKey;
|
||||
CF_CONNECTION_KEY connectionKey = {};
|
||||
};
|
||||
|
||||
VfsCfApi::VfsCfApi(QObject *parent)
|
||||
@ -146,9 +146,11 @@ void VfsCfApi::startImpl(const VfsSetupParams ¶ms)
|
||||
|
||||
void VfsCfApi::stop()
|
||||
{
|
||||
const auto result = cfapi::disconnectSyncRoot(std::move(d->connectionKey));
|
||||
if (!result) {
|
||||
qCCritical(lcCfApi) << "Disconnect failed for" << QDir::toNativeSeparators(params().filesystemPath) << ":" << result.error();
|
||||
if (d->connectionKey.Internal != 0) {
|
||||
const auto result = cfapi::disconnectSyncRoot(std::move(d->connectionKey));
|
||||
if (!result) {
|
||||
qCCritical(lcCfApi) << "Disconnect failed for" << QDir::toNativeSeparators(params().filesystemPath) << ":" << result.error();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user