private-sources.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 sourceslist;
  28. if (CmdL.FileList[1] != NULL)
  29. {
  30. sourceslist = _config->FindDir("Dir::Etc::sourceparts") + CmdL.FileList[1];
  31. if (!APT::String::Endswith(sourceslist, ".list"))
  32. sourceslist += ".list";
  33. } else {
  34. sourceslist = _config->FindFile("Dir::Etc::sourcelist");
  35. }
  36. HashString before;
  37. if (FileExists(sourceslist))
  38. before.FromFile(sourceslist);
  39. int lockfd = GetLock(sourceslist);
  40. if (lockfd < 0)
  41. return false;
  42. do {
  43. EditFileInSensibleEditor(sourceslist);
  44. _error->PushToStack();
  45. res = sl.Read(sourceslist);
  46. if (!res) {
  47. std::string outs;
  48. strprintf(outs, _("Failed to parse %s. Edit again? "), sourceslist.c_str());
  49. // FIXME: should we add a "restore previous" option here?
  50. res = !YnPrompt(outs.c_str(), true);
  51. }
  52. _error->RevertToStack();
  53. } while (res == false);
  54. close(lockfd);
  55. if (FileExists(sourceslist) && !before.VerifyFile(sourceslist)) {
  56. ioprintf(
  57. std::cout, _("Your '%s' file changed, please run 'apt-get update'."),
  58. sourceslist.c_str());
  59. }
  60. return true;
  61. }
  62. /*}}}*/