private-sources.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. do {
  30. EditFileInSensibleEditor(sourceslist);
  31. _error->PushToStack();
  32. res = sl.Read(sourceslist);
  33. if (!res) {
  34. _error->DumpErrors();
  35. strprintf(outs, _("Failed to parse %s. Edit again? "),
  36. sourceslist.c_str());
  37. std::cout << outs;
  38. // FIXME: should we add a "restore previous" option here?
  39. res = !YnPrompt(true);
  40. }
  41. _error->RevertToStack();
  42. } while (res == false);
  43. if (FileExists(sourceslist) && !before.VerifyFile(sourceslist)) {
  44. strprintf(
  45. outs, _("Your '%s' file changed, please run 'apt-get update'."),
  46. sourceslist.c_str());
  47. std::cout << outs << std::endl;
  48. }
  49. return true;
  50. }
  51. /*}}}*/