comparison hgrunner.cpp @ 189:6bb510abe4f1

* Handle failure to start processes at all (e.g. because executable path is wrong)
author Chris Cannam
date Mon, 20 Dec 2010 16:47:00 +0000
parents 07b908b4fa5f
children ff0d76dcb3b8
comparison
equal deleted inserted replaced
188:07b908b4fa5f 189:6bb510abe4f1
66 QString HgRunner::findExtension() 66 QString HgRunner::findExtension()
67 { 67 {
68 // If we haven't unbundled an extension, always do that (so that 68 // If we haven't unbundled an extension, always do that (so that
69 // it's available in case someone wants to use it later, e.g. to 69 // it's available in case someone wants to use it later, e.g. to
70 // fix a malfunctioning setup). But the path we actually prefer 70 // fix a malfunctioning setup). But the path we actually prefer
71 // is the one in the settings first; then the unbundled one; then 71 // is the one in the settings first, if it exists; then the
72 // anything in the path if for some reason unbundling failed 72 // unbundled one; then anything in the path if for some reason
73 // unbundling failed
73 74
74 QSettings settings; 75 QSettings settings;
75 settings.beginGroup("Locations"); 76 settings.beginGroup("Locations");
76 77
77 QString unbundled = getUnbundledFileName(); 78 QString unbundled = getUnbundledFileName();
78 if (!QFile(unbundled).exists()) { 79 if (!QFile(unbundled).exists()) {
79 unbundled = unbundleExtension(); 80 unbundled = unbundleExtension();
80 } 81 }
81 82
82 QString extpath = settings.value("extensionpath", "").toString(); 83 QString extpath = settings.value("extensionpath", "").toString();
83 if (extpath != "") return extpath; 84 if (extpath != "" && QFile(extpath).exists()) return extpath;
84 85
85 extpath = unbundled; 86 extpath = unbundled;
86 if (extpath == "") { 87 if (extpath == "") {
87 extpath = findInPath("easyhg.py", m_myDirPath, false); 88 extpath = findInPath("easyhg.py", m_myDirPath, false);
88 if (extpath == "easyhg.py") { 89 if (extpath == "easyhg.py") {
328 if (!checkPrompts(chunk)) { 329 if (!checkPrompts(chunk)) {
329 m_stdout += chunk; 330 m_stdout += chunk;
330 } 331 }
331 } 332 }
332 333
334 void HgRunner::error(QProcess::ProcessError)
335 {
336 finished(-1, QProcess::CrashExit);
337 }
338
333 void HgRunner::finished(int procExitCode, QProcess::ExitStatus procExitStatus) 339 void HgRunner::finished(int procExitCode, QProcess::ExitStatus procExitStatus)
334 { 340 {
335 // Save the current action and reset m_currentAction before we 341 // Save the current action and reset m_currentAction before we
336 // emit a signal to mark the completion; otherwise we may be 342 // emit a signal to mark the completion; otherwise we may be
337 // resetting the action after a slot has already tried to set it 343 // resetting the action after a slot has already tried to set it
341 347
342 m_isRunning = false; 348 m_isRunning = false;
343 m_currentAction = HgAction(); 349 m_currentAction = HgAction();
344 350
345 closeProcInput(); 351 closeProcInput();
346 delete m_proc; 352 m_proc->deleteLater();
347 m_proc = 0; 353 m_proc = 0;
348 354
349 if (completedAction.action == ACT_NONE) { 355 if (completedAction.action == ACT_NONE) {
350 DEBUG << "HgRunner::finished: WARNING: completed action is ACT_NONE" << endl; 356 DEBUG << "HgRunner::finished: WARNING: completed action is ACT_NONE" << endl;
351 } else { 357 } else {
444 env.insert("LC_ALL", "en_US.utf8"); 450 env.insert("LC_ALL", "en_US.utf8");
445 env.insert("HGPLAIN", "1"); 451 env.insert("HGPLAIN", "1");
446 m_proc->setProcessEnvironment(env); 452 m_proc->setProcessEnvironment(env);
447 453
448 connect(m_proc, SIGNAL(started()), this, SLOT(started())); 454 connect(m_proc, SIGNAL(started()), this, SLOT(started()));
455 connect(m_proc, SIGNAL(error(QProcess::ProcessError)),
456 this, SLOT(error(QProcess::ProcessError)));
449 connect(m_proc, SIGNAL(finished(int, QProcess::ExitStatus)), 457 connect(m_proc, SIGNAL(finished(int, QProcess::ExitStatus)),
450 this, SLOT(finished(int, QProcess::ExitStatus))); 458 this, SLOT(finished(int, QProcess::ExitStatus)));
451 connect(m_proc, SIGNAL(readyReadStandardOutput()), 459 connect(m_proc, SIGNAL(readyReadStandardOutput()),
452 this, SLOT(dataReadyStdout())); 460 this, SLOT(dataReadyStdout()));
453 connect(m_proc, SIGNAL(readyReadStandardError()), 461 connect(m_proc, SIGNAL(readyReadStandardError()),