private-sources.cc 2.1 KB

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