comparison src/hgrunner.cpp @ 444:66ec8b2ee946

Provide auth key and file information to easyhg extension
author Chris Cannam
date Tue, 28 Jun 2011 15:59:13 +0100
parents 005633eed862
children 856da063d76e
comparison
equal deleted inserted replaced
443:459b140032d4 444:66ec8b2ee946
25 #include <QDialog> 25 #include <QDialog>
26 #include <QLabel> 26 #include <QLabel>
27 #include <QVBoxLayout> 27 #include <QVBoxLayout>
28 #include <QSettings> 28 #include <QSettings>
29 #include <QInputDialog> 29 #include <QInputDialog>
30 #include <QDesktopServices>
30 #include <QTemporaryFile> 31 #include <QTemporaryFile>
31 #include <QDir> 32 #include <QDir>
32 33
33 #include <iostream> 34 #include <iostream>
34 #include <errno.h> 35 #include <errno.h>
66 closeTerminal(); 67 closeTerminal();
67 if (m_proc) { 68 if (m_proc) {
68 m_proc->kill(); 69 m_proc->kill();
69 m_proc->deleteLater(); 70 m_proc->deleteLater();
70 } 71 }
72 if (m_authFilePath != "") {
73 QFile(m_authFilePath).remove();
74 }
75 //!!! and remove any other misc auth file paths...
71 } 76 }
72 77
73 QString HgRunner::getUnbundledFileName() 78 QString HgRunner::getUnbundledFileName()
74 { 79 {
75 return SettingsDialog::getUnbundledExtensionFileName(); 80 return SettingsDialog::getUnbundledExtensionFileName();
384 m_queue.pop_front(); 389 m_queue.pop_front();
385 DEBUG << "checkQueue: have action: running " << toRun.action << endl; 390 DEBUG << "checkQueue: have action: running " << toRun.action << endl;
386 startCommand(toRun); 391 startCommand(toRun);
387 } 392 }
388 393
394 QStringList HgRunner::addExtensionOptions(QStringList params)
395 {
396 QString extpath = getExtensionLocation();
397 if (extpath == "") {
398 DEBUG << "HgRunner::addExtensionOptions: Failed to get extension location" << endl;
399 return params;
400 }
401
402 if (m_authFilePath == "") {
403
404 QByteArray key = randomKey();
405 if (key == QByteArray()) {
406 DEBUG << "HgRunner::addExtensionOptions: Failed to get proper auth key" << endl;
407 return params;
408 }
409 QString key16 = QString::fromLocal8Bit(key.toBase64()).left(16);
410
411 QByteArray fileExt = randomKey();
412 if (fileExt == QByteArray()) {
413 DEBUG << "HgRunner::addExtensionOptions: Failed to get proper auth file ext" << endl;
414 return params;
415 }
416 QString fileExt16 = QString::fromLocal8Bit(fileExt.toBase64()).left(16)
417 .replace('+', '-').replace('/', '.');
418 QString path = QDesktopServices::storageLocation
419 (QDesktopServices::CacheLocation);
420 QDir().mkpath(path);
421 if (path == "") {
422 DEBUG << "HgRunner::addExtensionOptions: Failed to get cache location" << endl;
423 return params;
424 }
425
426 m_authKey = key16;
427 m_authFilePath = QString("%1/easyhg_%2.dat").arg(path).arg(fileExt16);
428 }
429
430 params.push_front(QString("easyhg.authkey=%1").arg(m_authKey));
431 params.push_front("--config");
432
433 params.push_front(QString("easyhg.authfile=%1").arg(m_authFilePath));
434 params.push_front("--config");
435
436 // Looks like this one must be without quotes, even though the SSH
437 // one above only works on Windows if it has quotes (at least where
438 // there is a space in the path). Odd
439 params.push_front(QString("extensions.easyhg=%1").arg(extpath));
440 params.push_front("--config");
441
442 return params;
443 }
444
389 void HgRunner::startCommand(HgAction action) 445 void HgRunner::startCommand(HgAction action)
390 { 446 {
391 QString executable = action.executable; 447 QString executable = action.executable;
392 bool interactive = false; 448 bool interactive = false;
393 QStringList params = action.params; 449 QStringList params = action.params;
413 } 469 }
414 470
415 if (action.mayBeInteractive()) { 471 if (action.mayBeInteractive()) {
416 params.push_front("ui.interactive=true"); 472 params.push_front("ui.interactive=true");
417 params.push_front("--config"); 473 params.push_front("--config");
418
419 if (settings.value("useextension", true).toBool()) { 474 if (settings.value("useextension", true).toBool()) {
420 QString extpath = getExtensionLocation(); 475 params = addExtensionOptions(params);
421 // Looks like this one must be without quotes, even though the SSH
422 // one above only works on Windows if it has quotes (at least where
423 // there is a space in the path). Odd
424 params.push_front(QString("extensions.easyhg=%1").arg(extpath));
425 params.push_front("--config");
426 } 476 }
427 interactive = true; 477 interactive = true;
428 } 478 }
429 479
430 //!!! want an option to use the mercurial_keyring extension as well 480 //!!! want an option to use the mercurial_keyring extension as well