forked from openkylin/ukui-search
!18 Solve the problem that the dir watcher's dbus crashed because of deadlock. Add the support for nvme device. Add the dir path check of searchable dir for direct search.
Merge pull request !18 from 白俊杰/1020upstream
This commit is contained in:
commit
796d13252d
|
@ -214,7 +214,7 @@ void DirWatcher::mountAddCallback(GVolumeMonitor *monitor, GMount *gmount, DirWa
|
||||||
if (volume) {
|
if (volume) {
|
||||||
bool canEject = g_volume_can_eject(volume);
|
bool canEject = g_volume_can_eject(volume);
|
||||||
QString devName = g_volume_get_identifier(volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
|
QString devName = g_volume_get_identifier(volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
|
||||||
if (canEject and devName.contains(QRegExp("/sd[a-z][1-9]"))) {
|
if (canEject and devName.contains(QRegExp("/nvme[0-9]+n[0-9]+p[0-9]+|/sd[a-z][0-9]+"))) {
|
||||||
QMutexLocker locker(&s_mutex);
|
QMutexLocker locker(&s_mutex);
|
||||||
pThis->m_currentUDiskDeviceList.append(devName.section("/", -1));
|
pThis->m_currentUDiskDeviceList.append(devName.section("/", -1));
|
||||||
}
|
}
|
||||||
|
@ -253,6 +253,7 @@ void DirWatcher::mountRemoveCallback(GVolumeMonitor *monitor, GMount *gmount, Di
|
||||||
if (removedUri.startsWith("file:///")) {
|
if (removedUri.startsWith("file:///")) {
|
||||||
QString removedMountPoint = g_filename_from_uri(removedUri.toUtf8().constData(), nullptr, nullptr);
|
QString removedMountPoint = g_filename_from_uri(removedUri.toUtf8().constData(), nullptr, nullptr);
|
||||||
pThis->m_blackListOfIndex.removeAll(removedMountPoint);
|
pThis->m_blackListOfIndex.removeAll(removedMountPoint);
|
||||||
|
locker.unlock();
|
||||||
QStringList indexableDirList = pThis->currentIndexableDir();
|
QStringList indexableDirList = pThis->currentIndexableDir();
|
||||||
//卸载目录下存在已索引目录时,通知索引服务删除对应目录
|
//卸载目录下存在已索引目录时,通知索引服务删除对应目录
|
||||||
for (const QString &indexableDir : indexableDirList) {
|
for (const QString &indexableDir : indexableDirList) {
|
||||||
|
@ -261,6 +262,7 @@ void DirWatcher::mountRemoveCallback(GVolumeMonitor *monitor, GMount *gmount, Di
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//处理子卷情况
|
//处理子卷情况
|
||||||
|
locker.relock();
|
||||||
for (auto t = pThis->m_infoOfSubvolume.constBegin(); t != pThis->m_infoOfSubvolume.constEnd(); t++) {
|
for (auto t = pThis->m_infoOfSubvolume.constBegin(); t != pThis->m_infoOfSubvolume.constEnd(); t++) {
|
||||||
if (removedMountPoint.startsWith(t.value() + "/")) {
|
if (removedMountPoint.startsWith(t.value() + "/")) {
|
||||||
pThis->m_blackListOfIndex.removeAll(removedMountPoint.replace(t.value(), t.key()));
|
pThis->m_blackListOfIndex.removeAll(removedMountPoint.replace(t.value(), t.key()));
|
||||||
|
@ -440,7 +442,12 @@ void DirWatcher::initData()
|
||||||
<< "/sys" << "/proc" << "/srv" << "/sbin" << "/run" << "/opt";
|
<< "/sys" << "/proc" << "/srv" << "/sbin" << "/run" << "/opt";
|
||||||
|
|
||||||
//目前方案:可搜索目录(服务)默认根目录,可搜索目录(应用)默认家目录和/data目录
|
//目前方案:可搜索目录(服务)默认根目录,可搜索目录(应用)默认家目录和/data目录
|
||||||
m_searchableListForApplication << "/data" << QDir::homePath();
|
QDir dir("/data");
|
||||||
|
if (dir.exists()) {
|
||||||
|
m_searchableListForApplication << "/data";
|
||||||
|
}
|
||||||
|
m_searchableListForApplication << QDir::homePath();
|
||||||
|
|
||||||
m_searchableDirList << "/";
|
m_searchableDirList << "/";
|
||||||
|
|
||||||
//init auto mounted device list
|
//init auto mounted device list
|
||||||
|
@ -474,7 +481,7 @@ void DirWatcher::initData()
|
||||||
GVolume *volume = (GVolume*)g_list_nth_data(list, i);
|
GVolume *volume = (GVolume*)g_list_nth_data(list, i);
|
||||||
QString udiskDevName = g_volume_get_identifier(volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
|
QString udiskDevName = g_volume_get_identifier(volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
|
||||||
bool canEject = g_volume_can_eject(volume);
|
bool canEject = g_volume_can_eject(volume);
|
||||||
if (canEject and udiskDevName.contains(QRegExp("/sd[a-z][1-9]"))) {
|
if (canEject and udiskDevName.contains(QRegExp("/nvme[0-9]+n[0-9]+p[0-9]+|/sd[a-z][0-9]+"))) {
|
||||||
qDebug() << "udiskDevName:" << udiskDevName.section("/",-1);
|
qDebug() << "udiskDevName:" << udiskDevName.section("/",-1);
|
||||||
m_currentUDiskDeviceList.append(udiskDevName.section("/",-1));
|
m_currentUDiskDeviceList.append(udiskDevName.section("/",-1));
|
||||||
}
|
}
|
||||||
|
@ -519,8 +526,8 @@ void DirWatcher::handleDisk()
|
||||||
m_currentMountedDeviceInfo.clear();
|
m_currentMountedDeviceInfo.clear();
|
||||||
m_repeatedlyMountedDeviceInfo.clear();
|
m_repeatedlyMountedDeviceInfo.clear();
|
||||||
for (QStorageInfo &storage: QStorageInfo::mountedVolumes()) {
|
for (QStorageInfo &storage: QStorageInfo::mountedVolumes()) {
|
||||||
//遍历当前系统所有挂载的,且以sd*开头的存储设备
|
//遍历当前系统所有挂载的,且以sd*和nvme开头的存储设备
|
||||||
if (storage.isValid() and storage.isReady() and QString(storage.device()).contains(QRegExp("/sd[a-z][1-9]"))) {
|
if (storage.isValid() and storage.isReady() and QString(storage.device()).contains(QRegExp("/nvme[0-9]+n[0-9]+p[0-9]+|/sd[a-z][0-9]+"))) {
|
||||||
m_currentMountedDeviceInfo[storage.device()].append(storage.rootPath());
|
m_currentMountedDeviceInfo[storage.device()].append(storage.rootPath());
|
||||||
//存储非子卷的重复挂载设备
|
//存储非子卷的重复挂载设备
|
||||||
if (m_currentMountedDeviceInfo.value(storage.device()).length() > 1 and storage.subvolume().isEmpty()) {
|
if (m_currentMountedDeviceInfo.value(storage.device()).length() > 1 and storage.subvolume().isEmpty()) {
|
||||||
|
@ -574,7 +581,7 @@ void DirWatcher::handleDisk()
|
||||||
void DirWatcher::handleAddedUDiskDevice(QDBusMessage msg)
|
void DirWatcher::handleAddedUDiskDevice(QDBusMessage msg)
|
||||||
{
|
{
|
||||||
QDBusObjectPath objPath = msg.arguments().at(0).value<QDBusObjectPath>();
|
QDBusObjectPath objPath = msg.arguments().at(0).value<QDBusObjectPath>();
|
||||||
if (objPath.path().contains(QRegExp("/sd[a-z][1-9]"))) {
|
if (objPath.path().contains(QRegExp("/nvme[0-9]+n[0-9]+p[0-9]+|/sd[a-z][0-9]+"))) {
|
||||||
QMutexLocker locker(&s_mutex);
|
QMutexLocker locker(&s_mutex);
|
||||||
m_currentUDiskDeviceList.append(objPath.path().section("/",-1));
|
m_currentUDiskDeviceList.append(objPath.path().section("/",-1));
|
||||||
qDebug() << "Add Udisk:" << m_currentUDiskDeviceList;
|
qDebug() << "Add Udisk:" << m_currentUDiskDeviceList;
|
||||||
|
@ -585,7 +592,7 @@ void DirWatcher::handleRemovedUDiskDevice(QDBusMessage msg)
|
||||||
{
|
{
|
||||||
Q_EMIT this->udiskRemoved();
|
Q_EMIT this->udiskRemoved();
|
||||||
QDBusObjectPath objPath = msg.arguments().at(0).value<QDBusObjectPath>();
|
QDBusObjectPath objPath = msg.arguments().at(0).value<QDBusObjectPath>();
|
||||||
if (objPath.path().contains(QRegExp("/sd[a-z][1-9]"))) {
|
if (objPath.path().contains(QRegExp("/nvme[0-9]+n[0-9]+p[0-9]+|/sd[a-z][0-9]+"))) {
|
||||||
QMutexLocker locker(&s_mutex);
|
QMutexLocker locker(&s_mutex);
|
||||||
m_removedUDiskDevice = objPath.path().section("/",-1);
|
m_removedUDiskDevice = objPath.path().section("/",-1);
|
||||||
m_currentUDiskDeviceList.removeAll(m_removedUDiskDevice);
|
m_currentUDiskDeviceList.removeAll(m_removedUDiskDevice);
|
||||||
|
|
Loading…
Reference in New Issue