OEUpdateManager.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <QProcess>
  2. #include <QDir>
  3. #include "QsLog.h"
  4. #include "OEUpdateManager.h"
  5. #include "SystemComponent.h"
  6. ///////////////////////////////////////////////////////////////////////////////////////////////////
  7. QString OEUpdateManager::HaveUpdate()
  8. {
  9. return "";
  10. }
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////
  12. bool OEUpdateManager::applyUpdate(const QString& version)
  13. {
  14. return true;
  15. }
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////
  17. void OEUpdateManager::doUpdate(const QString& version)
  18. {
  19. // grab the update file
  20. QString packagePath = GetPath("", version, true);
  21. QDir packageDir(packagePath);
  22. QStringList updateFiles = packageDir.entryList(QStringList( "*.tar"), QDir::Files, QDir::Time);
  23. if (updateFiles.size())
  24. {
  25. // copy the update files to /storage/.update
  26. QString destUpdatePath = "/storage/.update/" + updateFiles.at(0);
  27. if (packageDir.rename(packagePath + updateFiles.at(0), destUpdatePath))
  28. {
  29. if (isMiniUpdateArchive(destUpdatePath))
  30. {
  31. // if we have a miniupdate, just exit
  32. QLOG_DEBUG() << "Exiting to apply application update " << destUpdatePath;
  33. SystemComponent::Get().exit();
  34. }
  35. else
  36. {
  37. // now reboot to do the update
  38. QLOG_DEBUG() << "Rebooting to apply system update " << destUpdatePath;
  39. QProcess::startDetached("reboot");
  40. }
  41. }
  42. }
  43. }
  44. ///////////////////////////////////////////////////////////////////////////////////////////////////
  45. bool OEUpdateManager::isMiniUpdateArchive(QString archivePath)
  46. {
  47. QProcess process;
  48. process.start("/bin/tar", QStringList() << "-tf" << archivePath);
  49. if (process.waitForFinished(1000) && (process.exitCode() == 0))
  50. {
  51. QByteArray output = process.readAllStandardOutput();
  52. return output.contains(QByteArray("bin/") + Names::MainName().toUtf8());
  53. }
  54. else
  55. {
  56. QLOG_ERROR() << "Unable to list update archive files : " << QString(process.readAllStandardError());
  57. }
  58. return false;
  59. }