-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsshfilecreationwatcher.cpp
57 lines (50 loc) · 1.78 KB
/
sshfilecreationwatcher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "sshfilecreationwatcher.h"
#include <QDebug>
SshFileCreationWatcher::SshFileCreationWatcher(QString ssh_details, QObject *parent) :
QThread(parent),
ssh_remote_access(ssh_details),
timeout(5000)
{
connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)),
this, SLOT(ssh_check_finished(int,QProcess::ExitStatus)));
}
void SshFileCreationWatcher::run() {
}
void SshFileCreationWatcher::ssh_check_finished(int exitcode, QProcess::ExitStatus status) {
process.waitForFinished();
qDebug() << process.readAll() << process.readAllStandardError();
if(exitcode==0 || status != QProcess::NormalExit) {
emit file_created();
}
}
void SshFileCreationWatcher::watch_for_file(QString newfilename) {
filename = newfilename;
process.start(
"ssh",
QStringList()
<< ssh_remote_access
<< "bash"
<< "-c"
<< ( QString("\"while [ ! -f '%1' ] ; do sleep 1 ; done\"").arg(filename) )
);
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
qDebug() << process.program() << process.arguments();
#endif
if(!process.waitForStarted()) {
emit terminate();
}
}
void SshFileCreationWatcher::remove_file() {
disconnect(&process, SIGNAL(finished(int,QProcess::ExitStatus)),
this, SLOT(ssh_check_finished(int,QProcess::ExitStatus)));
process.start( "ssh", QStringList() << ssh_remote_access << "rm" << filename );
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
qDebug() << process.program() << process.arguments();
#endif
if(!process.waitForStarted()) {
emit terminate();
}
process.waitForFinished();
qDebug() << process.readAll() << process.readAllStandardError();
emit file_removed();
}