Permalink
Browse files

Try to obtain USB bus and device number from device name if unavailab…

…le in URI. (#6243)

In 1.37.2, gvfs switched to URIs that remain consistent across USB device
re-enumerations. This removed the usb bus and device numbers from the URI. In
the case that these values aren't found in the URI, try to parse Unix device
name property and pass results as query params on the URL. Pay attention to
these params in MtpConnection.

See gvfs commits 3a7bb06b and efc76d0c for reference.
  • Loading branch information...
jbroadus authored and hatstand committed Jan 2, 2019
1 parent 544a1d1 commit 74fa386c908f64ed52aebd5b03453b62132360eb
Showing with 26 additions and 10 deletions.
  1. +16 −6 src/devices/giolister.cpp
  2. +10 −4 src/devices/mtpconnection.cpp
@@ -169,10 +169,12 @@ QVariantMap GioLister::DeviceHardwareInfo(const QString& id) {
QList<QUrl> GioLister::MakeDeviceUrls(const QString& id) {
QString mount_point;
QString uri;
QString unix_device;
{
QMutexLocker l(&mutex_);
mount_point = devices_[id].mount_path;
uri = devices_[id].mount_uri;
unix_device = devices_[id].volume_unix_device;
}

// gphoto2 gives invalid hostnames with []:, characters in
@@ -182,12 +184,20 @@ QList<QUrl> GioLister::MakeDeviceUrls(const QString& id) {

QList<QUrl> ret;

// Special case for file:// GIO URIs - we have to check whether they point
// to an ipod.
if (url.isValid() && url.scheme() == "file") {
ret << MakeUrlFromLocalPath(url.path());
} else {
ret << url;
if (url.isValid()) {
QRegExp device_re("usb/(\\d+)/(\\d+)");
if (device_re.indexIn(unix_device) >= 0) {
url.addQueryItem("busnum", device_re.cap(1));
url.addQueryItem("devnum", device_re.cap(2));
}

// Special case for file:// GIO URIs - we have to check whether they point
// to an ipod.
if (url.scheme() == "file") {
ret << MakeUrlFromLocalPath(url.path());
} else {
ret << url;
}
}

ret << MakeUrlFromLocalPath(mount_point);
@@ -26,14 +26,20 @@ MtpConnection::MtpConnection(const QUrl& url) : device_(nullptr) {
// Parse the URL
QRegExp host_re("^usb-(\\d+)-(\\d+)$");

if (host_re.indexIn(hostname) == -1) {
unsigned int bus_location;
unsigned int device_num;

if (host_re.indexIn(hostname) >= 0) {
bus_location = host_re.cap(1).toUInt();
device_num = host_re.cap(2).toUInt();
} else if (url.hasQueryItem("busnum")) {
bus_location = url.queryItemValue("busnum").toUInt();
device_num = url.queryItemValue("devnum").toUInt();
} else {
qLog(Warning) << "Invalid MTP device:" << hostname;
return;
}

const unsigned int bus_location = host_re.cap(1).toInt();
const unsigned int device_num = host_re.cap(2).toInt();

if (url.hasQueryItem("vendor")) {
LIBMTP_raw_device_t* raw_device =
(LIBMTP_raw_device_t*)malloc(sizeof(LIBMTP_raw_device_t));

0 comments on commit 74fa386

Please sign in to comment.