Commit ba96d3b9 authored by Harald Sitter's avatar Harald Sitter 🌈
Browse files

smb: guard against duplicated service discoveries

Summary:
if both dnssd and wsdiscovery have the same server on offer we'd create
duplicated entries. instead keep track of the discovered names and only
use the first discovery. notably happens when using wsdd on linux where
samba would also register itself on dnssd.

for ease of access and to not have to roundtrip through udsentry, discovery
objects now have a udsName function that is meant to be the exact name
used for the udsentry.

Test Plan:
- have samba
- run wsdd.py from https://github.com/christgau/wsdd
- server only shows up once

Reviewers: ngraham

Reviewed By: ngraham

Subscribers: kde-frameworks-devel, kfm-devel

Tags: #dolphin, #frameworks

Differential Revision: https://phabricator.kde.org/D28078
parent 2f87632b
......@@ -31,6 +31,7 @@ public:
Discovery();
virtual ~Discovery();
virtual QString udsName() const = 0;
virtual KIO::UDSEntry toEntry() const = 0;
};
......
......@@ -26,10 +26,15 @@ DNSSDDiscovery::DNSSDDiscovery(KDNSSD::RemoteService::Ptr service)
{
}
QString DNSSDDiscovery::udsName() const
{
return m_service->serviceName();
}
KIO::UDSEntry DNSSDDiscovery::toEntry() const
{
KIO::UDSEntry entry;
entry.fastInsert(KIO::UDSEntry::UDS_NAME, m_service->serviceName());
entry.fastInsert(KIO::UDSEntry::UDS_NAME, udsName());
entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
entry.fastInsert(KIO::UDSEntry::UDS_ACCESS, (S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH));
......
......@@ -32,6 +32,7 @@ class DNSSDDiscovery : public Discovery
{
public:
DNSSDDiscovery(KDNSSD::RemoteService::Ptr service);
QString udsName() const override;
KIO::UDSEntry toEntry() const override;
private:
......
......@@ -509,6 +509,7 @@ void SMBSlave::listDir(const QUrl &kurl)
QEventLoop e;
UDSEntryList list;
QStringList discoveredNames;
const auto flushEntries = [this, &list]() {
if (list.isEmpty()) {
......@@ -538,7 +539,13 @@ void SMBSlave::listDir(const QUrl &kurl)
const QList<Discoverer *> discoverers {&d, &w};
auto appendDiscovery = [&](const Discovery::Ptr &discovery) { list.append(discovery->toEntry()); };
auto appendDiscovery = [&](const Discovery::Ptr &discovery) {
if (discoveredNames.contains(discovery->udsName())) {
return;
}
discoveredNames << discovery->udsName();
list.append(discovery->toEntry());
};
auto maybeFinished = [&] { // finishes if all discoveries finished
bool allFinished = true;
......
......@@ -295,10 +295,15 @@ WSDiscovery::WSDiscovery(const QString &computer, const QString &remote)
{
}
QString WSDiscovery::udsName() const
{
return m_computer;
}
KIO::UDSEntry WSDiscovery::toEntry() const
{
KIO::UDSEntry entry;
entry.fastInsert(KIO::UDSEntry::UDS_NAME, m_computer);
entry.fastInsert(KIO::UDSEntry::UDS_NAME, udsName());
entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
entry.fastInsert(KIO::UDSEntry::UDS_ACCESS, (S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH));
......
......@@ -41,7 +41,7 @@ class WSDiscovery : public Discovery
public:
WSDiscovery(const QString &computer, const QString &remote);
QString udsName() const override;
KIO::UDSEntry toEntry() const override;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment