Try to obtain USB bus and device number from device name if unavailable 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.
This commit is contained in:
Jim Broadus 2019-01-02 07:06:22 -08:00 committed by John Maguire
parent 544a1d1eff
commit 74fa386c90
2 changed files with 26 additions and 10 deletions

View File

@ -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);

View File

@ -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));