move unmount logic from Partition to FileSystem

This commit is contained in:
Chantara Tith 2016-05-13 23:27:23 +07:00 committed by Andrius Štikonas
parent 3bfb0b4b5b
commit 2a12571d44
7 changed files with 17 additions and 23 deletions

View File

@ -320,17 +320,7 @@ bool Partition::unmount(Report& report)
while (success) { while (success) {
if (fileSystem().canUnmount(deviceNode())) { if (fileSystem().canUnmount(deviceNode())) {
success = fileSystem().unmount(deviceNode()); success = fileSystem().unmount(report, deviceNode());
if (success)
setMountPoint(QString());
} else {
ExternalCommand umountCmd(report,
QStringLiteral("umount"),
{ QStringLiteral("--verbose"),
deviceNode() });
if (!umountCmd.run() || umountCmd.exitCode() != 0)
success = false;
} }
KMountPoint::List mountPoints = KMountPoint::currentMountPoints(KMountPoint::NeedRealDeviceName); KMountPoint::List mountPoints = KMountPoint::currentMountPoints(KMountPoint::NeedRealDeviceName);

View File

@ -410,10 +410,14 @@ bool FileSystem::mount(const QString &deviceNode, const QString &mountPoint)
@param mountPoint the mount point the FileSystem is mounted on @param mountPoint the mount point the FileSystem is mounted on
@return true on success @return true on success
*/ */
bool FileSystem::unmount(const QString& mountPoint) bool FileSystem::unmount(Report& report, const QString& deviceNode)
{ {
Q_UNUSED(mountPoint); ExternalCommand umountCmd( report,
QStringLiteral("umount"),
{ QStringLiteral("--verbose"),
deviceNode });
if ( umountCmd.run() && umountCmd.exitCode() == 0 )
return true;
return false; return false;
} }

View File

@ -179,14 +179,14 @@ public:
return false; /**< @return true if this FileSystem can be mounted */ return false; /**< @return true if this FileSystem can be mounted */
} }
virtual bool canUnmount(const QString&) const { virtual bool canUnmount(const QString&) const {
return false; /**< @return true if this FileSystem can be unmounted */ return true; /**< @return true if this FileSystem can be unmounted */
} }
virtual QString mountTitle() const; virtual QString mountTitle() const;
virtual QString unmountTitle() const; virtual QString unmountTitle() const;
virtual bool mount(const QString& deviceNode, const QString& mountPoint); virtual bool mount(const QString& deviceNode, const QString& mountPoint);
virtual bool unmount(const QString& deviceNode); virtual bool unmount(Report& report, const QString& deviceNode);
qint64 firstSector() const { qint64 firstSector() const {
return m_FirstSector; /**< @return the FileSystem's first sector */ return m_FirstSector; /**< @return the FileSystem's first sector */

View File

@ -139,9 +139,9 @@ bool linuxswap::mount(const QString& deviceNode, const QString& mountPoint)
return cmd.run(-1) && cmd.exitCode() == 0; return cmd.run(-1) && cmd.exitCode() == 0;
} }
bool linuxswap::unmount(const QString& deviceNode) bool linuxswap::unmount(Report& report, const QString& deviceNode)
{ {
ExternalCommand cmd(QStringLiteral("swapoff"), { deviceNode }); ExternalCommand cmd(report, QStringLiteral("swapoff"), { deviceNode });
return cmd.run(-1) && cmd.exitCode() == 0; return cmd.run(-1) && cmd.exitCode() == 0;
} }

View File

@ -56,7 +56,7 @@ public:
} }
virtual bool mount(const QString& deviceNode, const QString& mountPoint) override; virtual bool mount(const QString& deviceNode, const QString& mountPoint) override;
virtual bool unmount(const QString& deviceNode) override; virtual bool unmount(Report& report, const QString& deviceNode) override;
virtual QString mountTitle() const override; virtual QString mountTitle() const override;
virtual QString unmountTitle() const override; virtual QString unmountTitle() const override;

View File

@ -403,7 +403,7 @@ bool luks::mount(const QString& deviceNode, const QString& mountPoint)
return false; return false;
} }
bool luks::unmount(const QString& deviceNode) bool luks::unmount(Report& report, const QString& deviceNode)
{ {
if (!m_isCryptOpen) if (!m_isCryptOpen)
{ {
@ -427,14 +427,14 @@ bool luks::unmount(const QString& deviceNode)
if (m_innerFs->canUnmount(mapperNode)) if (m_innerFs->canUnmount(mapperNode))
{ {
if (m_innerFs->unmount(mapperNode)) if (m_innerFs->unmount(report, mapperNode))
{ {
m_isMounted = false; m_isMounted = false;
return true; return true;
} }
} }
else { else {
ExternalCommand unmountCmd( ExternalCommand unmountCmd( report,
QStringLiteral("umount"), QStringLiteral("umount"),
{ QStringLiteral("--verbose"), mapperNode }); { QStringLiteral("--verbose"), mapperNode });
if (unmountCmd.run() && unmountCmd.exitCode() == 0) if (unmountCmd.run() && unmountCmd.exitCode() == 0)

View File

@ -135,7 +135,7 @@ public:
void createInnerFileSystem(Type type); void createInnerFileSystem(Type type);
virtual bool mount(const QString& deviceNode, const QString& mountPoint) override; virtual bool mount(const QString& deviceNode, const QString& mountPoint) override;
virtual bool unmount(const QString& deviceNode) override; virtual bool unmount(Report& report, const QString& deviceNode) override;
virtual FileSystem::Type type() const override; virtual FileSystem::Type type() const override;