Fix SFTP unmount
REVIEW: 129993
This commit is contained in:
parent
3ed53ea469
commit
f2925b7661
2 changed files with 43 additions and 26 deletions
|
@ -54,8 +54,7 @@ Mounter::Mounter(SftpPlugin* sftp)
|
|||
Mounter::~Mounter()
|
||||
{
|
||||
qCDebug(KDECONNECT_PLUGIN_SFTP) << "Destroy mounter";
|
||||
//FIXME: We don't unmount becuase it crashes if we try to unmount while the filesystem is being used. Potential memory leak.
|
||||
//unmount();
|
||||
unmount(false);
|
||||
}
|
||||
|
||||
bool Mounter::wait()
|
||||
|
@ -78,7 +77,7 @@ void Mounter::onPakcageReceived(const NetworkPackage& np)
|
|||
if (np.get<bool>(QStringLiteral("stop"), false))
|
||||
{
|
||||
qCDebug(KDECONNECT_PLUGIN_SFTP) << "SFTP server stopped";
|
||||
unmount();
|
||||
unmount(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -96,9 +95,9 @@ void Mounter::onPakcageReceived(const NetworkPackage& np)
|
|||
* Q_EMIT mounted();
|
||||
*/
|
||||
|
||||
unmount();
|
||||
unmount(false);
|
||||
|
||||
m_proc = new KProcess(this);
|
||||
m_proc = new KProcess();
|
||||
m_proc->setOutputChannelMode(KProcess::MergedChannels);
|
||||
|
||||
connect(m_proc, &QProcess::started, this, &Mounter::onStarted);
|
||||
|
@ -148,11 +147,13 @@ void Mounter::onStarted()
|
|||
|
||||
//m_proc->setStandardOutputFile("/tmp/kdeconnect-sftp.out");
|
||||
//m_proc->setStandardErrorFile("/tmp/kdeconnect-sftp.err");
|
||||
connect(m_proc, &KProcess::readyReadStandardError, [this]() {
|
||||
qCDebug(KDECONNECT_PLUGIN_SFTP) << "stderr: " << m_proc->readAll();
|
||||
|
||||
auto proc = m_proc;
|
||||
connect(m_proc, &KProcess::readyReadStandardError, [proc]() {
|
||||
qCDebug(KDECONNECT_PLUGIN_SFTP) << "stderr: " << proc->readAll();
|
||||
});
|
||||
connect(m_proc, &KProcess::readyReadStandardOutput, [this]() {
|
||||
qCDebug(KDECONNECT_PLUGIN_SFTP) << "stdout:" << m_proc->readAll();
|
||||
connect(m_proc, &KProcess::readyReadStandardOutput, [proc]() {
|
||||
qCDebug(KDECONNECT_PLUGIN_SFTP) << "stdout:" << proc->readAll();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -179,7 +180,7 @@ void Mounter::onFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|||
Q_EMIT failed(i18n("Error when accessing to filesystem"));
|
||||
}
|
||||
|
||||
unmount();
|
||||
unmount(true);
|
||||
}
|
||||
|
||||
void Mounter::onMountTimeout()
|
||||
|
@ -196,18 +197,34 @@ void Mounter::start()
|
|||
m_connectTimer.start();
|
||||
}
|
||||
|
||||
void Mounter::unmount()
|
||||
void Mounter::unmount(bool finished)
|
||||
{
|
||||
qCDebug(KDECONNECT_PLUGIN_SFTP) << "Unmount" << m_proc;
|
||||
if (m_proc)
|
||||
{
|
||||
auto toDestroy = m_proc;
|
||||
m_proc = nullptr; //So we don't reenter this code path when onFinished gets called
|
||||
toDestroy->kill();
|
||||
delete toDestroy;
|
||||
if (!finished)
|
||||
{
|
||||
//Process is still running, we want to stop it
|
||||
//But when the finished signal come, we might have already gone.
|
||||
//Disconnect everything.
|
||||
m_proc->disconnect();
|
||||
m_proc->kill();
|
||||
|
||||
auto proc = m_proc;
|
||||
m_proc = nullptr;
|
||||
connect(proc, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
||||
[proc]() {
|
||||
qCDebug(KDECONNECT_PLUGIN_SFTP) << "Free" << proc;
|
||||
proc->deleteLater();
|
||||
});
|
||||
Q_EMIT unmounted();
|
||||
}
|
||||
else
|
||||
m_proc->deleteLater();
|
||||
|
||||
//Free mount point (won't always succeed if the path is in use)
|
||||
KProcess::execute(QStringList() << QStringLiteral("fusermount") << QStringLiteral("-u") << m_mountPoint, 10000);
|
||||
m_proc = nullptr;
|
||||
}
|
||||
m_started = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ private Q_SLOTS:
|
|||
void start();
|
||||
|
||||
private:
|
||||
void unmount();
|
||||
void unmount(bool finished);
|
||||
|
||||
private:
|
||||
SftpPlugin* m_sftp;
|
||||
|
|
Loading…
Reference in a new issue