private-sources.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <apt-pkg/hashes.h>
  2. #include <apti18n.h>
  3. #include "private-output.h"
  4. #include "private-sources.h"
  5. #include "private-utils.h"
  6. /* Interface discussion with donkult (for the future):
  7. apt [add-{archive,release,component}|edit|change-release|disable]-sources
  8. and be clever and work out stuff from the Release file
  9. */
  10. // EditSource - EditSourcesList /*{{{*/
  11. // ---------------------------------------------------------------------
  12. bool EditSources(CommandLine &CmdL)
  13. {
  14. bool res;
  15. pkgSourceList sl;
  16. std::string outs;
  17. std::string sourceslist;
  18. if (CmdL.FileList[1] != NULL)
  19. {
  20. sourceslist = _config->FindDir("Dir::Etc::sourceparts") + CmdL.FileList[1];
  21. if (!APT::String::Endswith(sourceslist, ".list"))
  22. sourceslist += ".list";
  23. } else {
  24. sourceslist = _config->FindFile("Dir::Etc::sourcelist");
  25. }
  26. HashString before;
  27. if (FileExists(sourceslist))
  28. before.FromFile(sourceslist);
  29. int lockfd = GetLock(sourceslist);
  30. if (lockfd < 0)
  31. return false;
  32. do {
  33. EditFileInSensibleEditor(sourceslist);
  34. _error->PushToStack();
  35. res = sl.Read(sourceslist);
  36. if (!res) {
  37. _error->DumpErrors();
  38. strprintf(outs, _("Failed to parse %s. Edit again? "),
  39. sourceslist.c_str());
  40. std::cout << outs;
  41. // FIXME: should we add a "restore previous" option here?
  42. res = !YnPrompt(true);
  43. }
  44. _error->RevertToStack();
  45. } while (res == false);
  46. close(lockfd);
  47. if (FileExists(sourceslist) && !before.VerifyFile(sourceslist)) {
  48. strprintf(
  49. outs, _("Your '%s' file changed, please run 'apt-get update'."),
  50. sourceslist.c_str());
  51. std::cout << outs << std::endl;
  52. }
  53. return true;
  54. }
  55. /*}}}*/