Make sure system is informed about the change of file system label.

This commit is contained in:
Andrius Štikonas 2018-04-13 15:54:51 +03:00
parent a6100aaa37
commit 07458efb91
3 changed files with 21 additions and 7 deletions

View File

@ -57,7 +57,6 @@ public:
RAID_Device, /* software RAID device */
};
protected:
explicit Device(std::shared_ptr<DevicePrivate> d_ptr, const QString& name, const QString& deviceNode, const qint64 logicalSectorSize, const qint64 totalLogicalSectors, const QString& iconName = QString(), Device::Type type = Device::Type::Disk_Device);
public:

View File

@ -18,6 +18,13 @@
#include "jobs/setfilesystemlabeljob.h"
#include "backend/corebackend.h"
#include "backend/corebackendmanager.h"
#include "backend/corebackenddevice.h"
#include "backend/corebackendpartitiontable.h"
#include "core/device_p.h"
#include "core/operationstack.h"
#include "core/partition.h"
#include "fs/filesystem.h"
@ -26,6 +33,8 @@
#include <KLocalizedString>
#include <memory>
/** Creates a new SetFileSystemLabelJob
@param p the Partition the FileSystem whose label is to be set is on
@param newlabel the new label
@ -61,7 +70,15 @@ bool SetFileSystemLabelJob::run(Report& parent)
partition().fileSystem().setLabel(label());
}
// FIXME: need to commit to device
// A hack to reread partition table (commit() should be called even on non DiskDevices)
Device dev(std::make_shared<DevicePrivate>(), QString(), QString(), 0, 0, QString(), Device::Type::Unknown_Device);
std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(dev);
if (backendDevice) {
std::unique_ptr<CoreBackendPartitionTable> backendPartitionTable = backendDevice->openPartitionTable();
if (backendPartitionTable)
backendPartitionTable->commit();
}
jobFinished(*report, rval);

View File

@ -28,8 +28,6 @@
#include "util/report.h"
#include "util/externalcommand.h"
#include <unistd.h>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
@ -54,9 +52,9 @@ bool SfdiskPartitionTable::open()
bool SfdiskPartitionTable::commit(quint32 timeout)
{
if ( !(ExternalCommand(QStringLiteral("udevadm"), { QStringLiteral("settle"), QStringLiteral("--timeout=") + QString::number(timeout) }).run() &&
ExternalCommand(QStringLiteral("blockdev"), { QStringLiteral("--rereadpt"), m_device->deviceNode() }).run()))
sleep(1);
ExternalCommand(QStringLiteral("udevadm"), { QStringLiteral("settle"), QStringLiteral("--timeout=") + QString::number(timeout) }).run();
ExternalCommand(QStringLiteral("blockdev"), { QStringLiteral("--rereadpt"), m_device->deviceNode() }).run();
ExternalCommand(QStringLiteral("udevadm"), { QStringLiteral("trigger") }).run();
return true;
}